-
Posts
969 -
Joined
-
Last visited
Everything posted by Destramic
-
i hope this helps you to understand my problem: but you'll need jquery plugin : http://jquery.com/ and cookies : http://plugins.jquery.com/project/Cookie <!DOCTYPE html> <html> <head> <script type="text/javascript" src="js/library/jquery.js"></script> <script type="text/javascript" src="js/library/jquery.cookie.js"></script> </head> <body> <script> $(document).ready(function() { function add_input(selector, fields, field_type, break_point) { var count = 1; var loop_count = 1; var fields_count = $.param(fields).split('&').length; var breakage_point; var field_name; $('div#add_' + selector).click(function() { $.each(fields, function(field_name, field_label) { breakage_point = fields_count * count; field_name = field_name + count; input_field = '<label for="' + field_name + '">' + field_label + ' ' + count + ' : </label><input id="'+ field_name +'" name="' + field_name + '" type="' + field_type + '" value="" />'; if (loop_count == breakage_point) { input_field += '<br />'; } $(input_field).appendTo('div#' + selector).hide().fadeIn(1200); loop_count++; }); count++; $.cookie(selector + '_count', count); if (count > 1) { $('div#remove_' + selector).hide().fadeIn(1200); } }); $('div#remove_' + selector).click(function() { var remove_field = ''; $.each(fields, function(field_name, field_label) { field_name = field_name + (count - 1); field_label = field_label + ' ' + (count - 1); var field_value = $('#' + field_name).val(); remove_field += $('<label for="' + field_name + '">' + field_label + ' : </label><input id="' + field_name + '" name="' + field_name + '" value="' + field_value + '" type="text">'); alert($('div#' + selector).html()); }); if (loop_count == breakage_point) { remove_field += '<br>'; } var replace = $('div#' + selector).html().replace(remove_field, ''); $('div#' + selector).html(replace); count--; $.cookie(selector + '_count', count); if (count < 3) { $('div#remove_' + selector).fadeOut(1200); } }); if ($.cookie(selector + '_count')) { var cookie_count = $.cookie(selector + '_count'); for (i=1; i < cookie_count; i++) { $('div#add_' + selector).click(); } } if (count < 3) { $('div#remove_' + selector).hide(); } } var fields = {'game_types' : 'Game Type - Name', 'game_types_abbreviated' : 'Game Type - Abbreviated'}; add_input('game_types', fields, 'text', 2); }); </script> <form method="post"> <label for="game_name">Game Name:</label> <input id="game_name" name="game_name" value="" type="text" /><br /><a></a> <label for="game_name_abbreviated">Game Name Abbreviated:</label> <input id="game_name_abbreviated" name="game_name_abbreviated" value="" type="text" /><br /> <div id="game_types"></div><br /> <div id="add_game_types">Add Game Type</div> <div id="remove_game_types">Remove Game Type</div> <input type="submit" value="Submit"> </form> </body> </html>
-
It's the first time i've come across it with javascript as i've never noticed this effect with any of my other scripts...are you sure this is normal to have a style automatically added to a tag?...and i'm currently using firefox web browser
-
yeah it does...can this be removed?...is this normal?
-
i have a page with no css or style sheet included but when view the html , $('selector').html(); is shows every tag, <input />, <br />, and <label> with style="display: inline;" in it...and i dont understand why if anyone can help please?
-
hey guy i have a script which will add fields to a div but when i view the div's html it has a <style> added to the input/label and break tags but i dont undertstand why...especially has the page hasnt got a style sheet yet...if anyone could help me undstand why this is happening please? html added to div input_field = '<label for="' + field_name + '">' + field_label + ' ' + count + ' : </label><input id="'+ field_name +'" name="' + field_name + '" type="' + field_type + '" value="" />'; html inside div <label style="display: inline;" for="game_types1">Game Type - Name 1 : </label><input style="display: inline;" id="game_types1" name="game_types1" value="" type="text"> thanks you
-
hey guys ive made a script which returns the field values (script below) but the problem i have is with this line here var cookie_value = $.cookie(id); cause if there isnt a cookie with that value which exists it casues the script not to work...can anyone help out here please on how i could get this to work correctly please? function remember_field_value(selector) { selector = '#' + selector; var id = $(selector).attr('id'); var cookie_value = $.cookie(id); if (cookie_value !== null) { if ($(selector).attr('type') == 'checkbox') { $(selector).attr('checked', cookie_value); } else if ($(selector).attr('type') == 'text') { $(selector).val(cookie_value); } else if ($(selector).attr('type') == 'select-one') { $('#' + cookie_value).attr('selected', 'selected'); } } $(selector).change(function() { if ($(selector).attr('type') == 'checkbox') { if ($(selector).attr('checked')) { $.cookie(id, true); } else { $.cookie(id, null); } } else if ($(selector).attr('type') == 'text') { var value = $(selector).val(); $.cookie(id, value); } else if ($(selector).attr('type') == 'select-one') { var option_id = $(selector + ' :selected').attr('id'); $.cookie(id, option_id); } }); }
-
$_SESSION['rows'] unsetting upon submit...
Destramic replied to billyp1970's topic in PHP Coding Help
submit your new code and i'll have a good look over it -
$_SESSION['rows'] unsetting upon submit...
Destramic replied to billyp1970's topic in PHP Coding Help
try echoing $rows after its been defined and see if you get a value...there' something obviously wrong at the top of the code but i cant see what -
Thanks it is actually for a json script...so that should do nicely...i'll give it a wirl when I get home...thanks again
-
im trying to create a javascript array but im doing something wrong...if anyone could tell me what im doing wrong please...thank you var fields = new array('game_type' : 'Game Type', 'game_abbreviation' : 'Game Abbreviation');
-
$_SESSION['rows'] unsetting upon submit...
Destramic replied to billyp1970's topic in PHP Coding Help
well if you look you have no entry/data in your rows...try giving rows a value then test again -
$_SESSION['rows'] unsetting upon submit...
Destramic replied to billyp1970's topic in PHP Coding Help
print_r($_SESSION['rows']); above line 45 and let me know what it returns please -
I think possibly javascript/jquery would be the best way to do this...so your for would be dynamic and wouldn't have to reload its self...but i'm not the best on how to do it...so i'd suggest to try in google jquery disable button and it should help hopefully
-
hey guys im trying to get the correct alert when the form is being used....for instance if a user changed the input value i want it to alert input...if checkbox is checked alert checkbox....and the same with select if option is selected but all i get is the script alerting input anytime i do anything to any field can someone please help me on how to divide these fields apart from each other....thank you <!DOCTYPE html> <html> <head> <script type="text/javascript" src="js/library/jquery.js"></script> <script type="text/javascript" src="js/library/jquery.cookie.js"></script> <style> div { display : inline; } </style> </head> <body> <script> $(document).ready(function() { function remember_field_value(selector) { $(selector).change(function() { if ($(selector + ':checkbox')) { alert('checkbox'); } else if ($(selector + ':input')) { alert('input'); } else if ($(selector + ':selected')) { alert('select'); } }); } remember_field_value('input#game_type1'); remember_field_value('input#tester'); remember_field_value('select#game'); }); </script> <form method="post"> <input id="game_type1" name="game_types[]" value=""/> <input id='tester' type="checkbox" name="team" value="other"> <select id='game'> <option>hello</option> <option>bye</option> </select> <input type="submit" value="Submit"> </form> </body> </html>
-
ok well ive sorted that out now and im able to run remove_game_type on click...but the only problem im having is removing the last game type added if anyone could help me with the correct syntax please? page here: <!DOCTYPE html> <html> <head> <script type="text/javascript" src="js/library/jquery.js"></script> <style> div { display : inline; } </style> </head> <body> <script> $(document).ready(function(){ var game_type_count = 1; $('#add_game_type').click(function() { game_type_count++; var game_type = $('<label for="game_type' + game_type_count + '">Game Type ' + game_type_count +' - Name : </label><input name=\"game_types[]\" id=\"game_type' + game_type_count + '\" type=\"text\" value=\"\" /><div id=\"remove_game_type\">x</div><br />'); $("label#game_type").text("Game Type 1 - Name :"); $("label#game_type_abbreviation").text("Game Type 1 - Abbreviation :"); $(game_type).appendTo('#game_types'); }); $('#remove_game_type').live('click',function(){ alert('remove'); $('#game_types').remove('<label for="game_type' + game_type_count + '">Game Type ' + game_type_count +' - Name : </label><input name=\"game_types[]\" id=\"game_type' + game_type_count + '\" type=\"text\" value=\"\" /><div id=\"remove_game_type\">x</div><br />'); if (game_type_count == 1) { $("label#game_type").text("Game Type - Name:"); } game_type_count--; }); }); </script> <label id="game_type" for="game_type1">Game Type - Name : </label><input id="game_type1" name="game_types[]" /> <label id="game_type_abbreviation" for="game_type1">Game Type - Abbreviation :</label><input id="game_type1" name="game_types[]" /> <br /><div id="game_types"></div><br /> <div id="add_game_type"> Add Game Type</div> </body> </html>
-
hey guys if you view/see the script below ive made it will add a input field on click and also adds a cross (X) by the side just incase that input field needs to be deleted. but the problem im having is: <div id=\"remove_game_type\">x</div> doesnt work or execute the $('#remove_game_type').click function if anyone could help please <!DOCTYPE html> <html> <head> <script type="text/javascript" src="js/library/jquery.js"></script> </head> <body> <script> $(document).ready(function(){ var count = 1; $('#add_game_type').click(function() { count++; var game_type = $('<label>Game Type ' + count +':</label><input name=\"game_type' + count + '\" id=\"\" type=\"text\" value=\"\" /><div id=\"remove_game_type\">x</div><br />'); $("label#game_type").text("Game Type 1:"); $('input[name$="game_type"]').attr("name", "game_type1"); $(game_type).appendTo('#game_types'); }); $('#remove_game_type').click(function() { alert('remove'); }); }); </script> <label id="game_type">Game Type:</label><input name="game_type" /> <div id="game_types"></div> <div id="add_game_type"> Add Game Type</div> </body> </html>
-
hey ive just finnished creating my dispacher class which works fine...im wanting to know what dispachstartloop() does for the dispatcher class...i see it in other frameworks...if anyone has any articles on this or help i'd be greatful...thank dispatcher.class.php <?php class Dispatcher { private $_controller; private $_action; private $_pararmeters; public function is_dispatchable() { if (method_exists($this->_controller, $this->_action)) { return true; } } public function format_controller_name($controller_name) { $controller_name = $controller_name . '_Controller'; return $controller_name; } public function dispatch($request, $response) { $controller_name = $request->get_controller_name(); $controller_name = $this->format_controller_name($controller_name); $this->_controller = new $controller_name; $this->_action = $request->get_action_name(); $this->_parameters = $request->get_parameters(); if ($this->is_dispatchable()) { call_user_func_array(array($this->_controller, $this->_action), $this->_parameters); } else { $response->set_exception(sprintf("Call to undefined method '%s'.<br />\n", $this->_action)); } } } ?>
-
or of course i could write a wrapper in my Front_Controller <?php class Front_Controller { public function add_route($route) { $this->_route->add_route($route) } } and do the same with the $this->_view->set_variable (create a wrapper) ?
-
thank you for your help and time you've really helped alot...i understand how the methd i explained wouldnt be so good...and i'll start to use private instead of protected....but when i comes to me using my View class and when i call to set_variables() in my Page_Controller i'd have to send the view object across in the constuctor like the routing object as you've exlained?...and that would be the best way?...thanks again
-
what about if i just set my attributes in my class to public so i can just get the route instance from there? <php class Front_Controller { public $_route; public function __construct() { $this->_route = new Router; ...load controller etc } } class Page_Controller { public function new_articles() { $this->_route->add_route("route here"); } } would that be good or considered as bad practice
-
ok i see and would i add the route in the method (page)? <?php class Sometest_Controller { private $_route; public function __construct(Router $_route_object) { $this->_route = $_route_object; } protected function news_atricles() { // so url will look like domain.co.uk/news/articles $this->_route->add_route('news/articles'); }
-
well here is my font controller im working on: <?php class Front_Controller { protected $_controller; protected $_request; protected $_route; protected $_inflect; public function __construct() { $this->_request = new Request; $this->_route = new Router($this); $this->_inflect = new Inflection; $this->_request->get_request(); $controller_name = $this->_request->get_controller_name(); $controller = ucfirst($controller_name) . '_Controller'; $model = '_' . $controller_name; $this->_controller = new $controller; $this->$model = new Model($this); } } ?> and this is where i would make sure the route is correct dispatch the page controller and load the action but im still a bit unclear where i would add a route (in the page controller)?
-
ok and the $route->add_route would be excited in the view template page (with the html) or the page controller?...thanks for you help
-
i like the idea of adding the route in the page controller or even in the view page itself $route->add_route('news/test'); but the problem there is that the front controller would load the page controller, method and display the page before you could compare route with url
-
im tying to design and make a routing system for my mvc framework but im wondering the best way to do this if anyone could help on how the design pattern would be. im thinking i would have a route config file which would contain all the routes for each file routes.config <?php $routes = array('news' => 'news/index'); ?> then the routing class which would get the correct route depeding on the request class and get the dispatch class to load the controller and action? if anyone could help on the best way to do this that would be great...thanks