niche Posted September 24, 2010 Share Posted September 24, 2010 What's the easiest way to flag a clicked item based on this snippet? Is it AJAX? Or, is there an easier way? <?phpsession_start();?><form method="post" action=""><input type="checkbox" name="bop1" value="yes" /> Check to print BOP1 <br /><input type="submit" value="submit" name="submit"><br /></form><br /> <form method="post" action=""><input type="checkbox" name="bop2" value="yes" /> Check to print BOP2<br /><input type="submit" value="submit" name="submit"><br /></form><br /> <form method="post" action=""><input type="checkbox" name="bop3" value="yes" /> Check to print BOP3<br /><input type="submit" value="submit" name="submit"><br /></form><br /> <?phpecho var_dump($_POST) .'<br/>';?> Link to comment Share on other sites More sharing options...
justsomeguy Posted September 24, 2010 Share Posted September 24, 2010 What do you mean by "flag a clicked item"? Link to comment Share on other sites More sharing options...
niche Posted September 24, 2010 Author Share Posted September 24, 2010 Based on my snippet, the checkbox would stay checked (after submission) or the text, after the checkbox, would change color after submission. I see this effect all the time, but don't know what it's called. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 24, 2010 Share Posted September 24, 2010 I don't know if that has a name. If you're using regular form submission, then you just check the value in $_POST and figure out what you want to do. If you're using ajax, then you send the value to the server, get the response, and figure out what you want to do. Link to comment Share on other sites More sharing options...
jeffman Posted September 24, 2010 Share Posted September 24, 2010 If you're using AJAX, the checked property won't change unless you tell it to. If it's a form, like jsg says, respond to the value from the POST data:<input type="checkbox" <?php echo isset($_POST['mycheckbox']) ? 'checked="checked"' : ''; ?> name="mycheckbox"> Link to comment Share on other sites More sharing options...
niche Posted September 24, 2010 Author Share Posted September 24, 2010 I've refined my question. Is there an example or tutorial that will let me change the color of text (or a button) in a way that's similar to changing anchor color with css (link, visited, hove, active). I tried to style the the input tag with those properties but it didn't work.I apologize if this just became a css question. Link to comment Share on other sites More sharing options...
niche Posted September 24, 2010 Author Share Posted September 24, 2010 The isset approach keeps checkbox1 after submission, but how do you keep checkbox1 checked after checkbox2 gets submitted so the page comes back with checkbox1 AND checkbox2 checked based on this example: <html><head><style type="text/css"></style></head><body><?phpsession_start();?><form method="post" action=""><input type="checkbox" <?php echo isset($_POST['mycheckbox1']) ? 'checked="checked"' : ''; ?> name="mycheckbox1"> Check to print BOP1 <br /><input type="submit" value="submit" name="submit"><br /></form><br /> <form method="post" action=""><input type="checkbox" <?php echo isset($_POST['mycheckbox2']) ? 'checked="checked"' : ''; ?> name="mycheckbox2"> Check to print BOP2<br /><input type="submit" value="submit" name="submit"><br /></form><br /> <form method="post" action=""><input type="checkbox" <?php echo isset($_POST['mycheckbox3']) ? 'checked="checked"' : ''; ?> name="mycheckbox3"> Check to print BOP3<br /><input type="submit" value="submit" name="submit"><br /></form><br /> <?phpecho var_dump($_POST) .'<br/>';?></body></html> Link to comment Share on other sites More sharing options...
ShadowMage Posted September 24, 2010 Share Posted September 24, 2010 Put 'em all in one form. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 24, 2010 Share Posted September 24, 2010 Or store them in the session.To change the classes, if you're using PHP then the easiest way is to just use PHP to check whether to print an extra class name onto the elements you want to change. If you're using Javascript there are several examples online to either add and remove classes to elements or set individual style properties. Link to comment Share on other sites More sharing options...
niche Posted September 24, 2010 Author Share Posted September 24, 2010 That's the way I had it until I realized the list of checkboxes could be very long. So I switched to individual forms.Would onclick be the solution. If so, I'll need familiarize myself. I haven't used it before. Link to comment Share on other sites More sharing options...
ShadowMage Posted September 24, 2010 Share Posted September 24, 2010 That's the way I had it until I realized the list of checkboxes could be very long. So I switched to individual forms.What does that have to do with anything? :)The number of elements in a form makes no difference at all.Would onclick be the solution. If so, I'll need familiarize myself. I haven't used it before.You could use the onclick event to send an AJAX request which could do whatever you needed to do with the submitted value, and then alter the clicked checkbox....if that's what you're asking. Link to comment Share on other sites More sharing options...
niche Posted September 24, 2010 Author Share Posted September 24, 2010 I like PHP. How are classes connected? Link to comment Share on other sites More sharing options...
niche Posted September 24, 2010 Author Share Posted September 24, 2010 if you're using PHP then the easiest way is to just use PHP to check whether to print an extra class name onto the elements you want to change.I don't understand how that would work. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 24, 2010 Share Posted September 24, 2010 You just use an if statement with an echo to decide whether or not to print a classname into the HTML tag. Link to comment Share on other sites More sharing options...
niche Posted September 24, 2010 Author Share Posted September 24, 2010 Class as in OPP? Link to comment Share on other sites More sharing options...
justsomeguy Posted September 25, 2010 Share Posted September 25, 2010 No, as in <div class="some_class_name"> Link to comment Share on other sites More sharing options...
jeffman Posted September 25, 2010 Share Posted September 25, 2010 As in:<td class="<?php echo isset($_POST['something']) ? 'bluecell' : 'pinkcell'; ?>">Which results in<td class="bluecell">or<td class="pinkcell">depending on the whether a form element with the name 'something' was posted to the server. Link to comment Share on other sites More sharing options...
niche Posted September 25, 2010 Author Share Posted September 25, 2010 OK (always looking for a chance to create my first class), but which property will display a checked checkbox? I just went through the property list and didn't see one that would to that. Link to comment Share on other sites More sharing options...
jeffman Posted September 25, 2010 Share Posted September 25, 2010 I thought I explained that in Post #5. Link to comment Share on other sites More sharing options...
niche Posted September 25, 2010 Author Share Posted September 25, 2010 I was going to ask where 'checked="checked"' came from (in fact I'd like to know how to interpret: ? 'checked="checked"' : ''). Is that another way to use class? Link to comment Share on other sites More sharing options...
niche Posted September 25, 2010 Author Share Posted September 25, 2010 I need to take back my last post and instead ask how checked="checked" can be worked into a class and how to interpret the question mark and colon in <?php echo isset($_POST['mycheckbox1']) ? 'checked="checked"' : ''; ?> Link to comment Share on other sites More sharing options...
niche Posted September 25, 2010 Author Share Posted September 25, 2010 I found the ternary reference.I can't imagine, though, how to work some part of <?php echo isset($_POST['mycheckbox3']) ? 'checked="checked"' : ''; ?> into a class (post #9). Link to comment Share on other sites More sharing options...
justsomeguy Posted September 25, 2010 Share Posted September 25, 2010 The checked attribute is not CSS, it's not a class. It's just a regular HTML attribute. Link to comment Share on other sites More sharing options...
niche Posted September 25, 2010 Author Share Posted September 25, 2010 I was hoping you'd say that. Thanks to justsomeguy, Deirdre's Dad, ShadowMage. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.