Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

keep checkbox checked

Status
Not open for further replies.

speedyrudolf

Programmer
Sep 2, 2009
27
RO
Hi. I'm having a pretty hard time figuring how to do something... In a nutshell, I have a form, when submitted it calls a php page that emails me the form, if it can't email it, it stores the form field values in a txt file, then calls up another php page, which is actually the form with the fields already populated (the field values are read from the file and assigned to the respective fields). What I'm having trouble with is some checkboxes and radios: they already have values assigned to them, so I don't know how to check them if they were previously checked.
Anyway...maybe part of the code will clear things up a bit:
Code:
<?php
$fis_txt=fgets($eroare, 102400);
$text_txt=fgets($eroare, 102400);
$nav_sel=fgets($eroare, 102400);
for($i=0; $i<22; $i++)
 {$navs.$i=fgets($eroare, 102400);}
?>

<html>
<input type="radio" name="Text" value="Fisier" onClick="Val_text();Cont_pag2();">Check the one that was previously checked
<input type="radio" name="Text" value="Text" onClick="Val_text();Cont_pag2();">Check the one that was previously checked
<input type="file" name="Fis_txt" size="100" value="<?php echo $fis_txt; ?>" onChange="Cont_pag2()">
<textarea name="Text_txt" cols="80" rows="10" value="<?php echo $text_txt; ?>" onKeyUp="Cont_pag2()">

<input type="checkbox" id="Navs0" name="Navs0" value="1" onClick="Cont_pag5_3()">Check it if it was previously checked, if not leave it unchecked
<input type="checkbox" id="Navs1" name="Navs1" value="1" onClick="Cont_pag5_3()">Check it if it was previously checked, if not leave it unchecked
<input type="checkbox" id="Navs2" name="Navs2" value="2" onClick="Cont_pag5_3()">Check it if it was previously checked, if not leave it unchecked
And so on until Navs21
</html>
Well...like I said, this is just a small part of the code...the entire file has about 80KB...
Anyway...If the checkbox was previously checked, in the txt file the respective line would say ON, if it was unchecked it would say OFF. And for the radios, the txt file would contain the value of the one that was checked.

So...How do I go and do that? Any help will be very much appreciated...
 
Hi

speedyrudolf said:
What I'm having trouble with is some checkboxes and radios: they already have values assigned to them, so I don't know how to check them if they were previously checked.
Checkboxes and radio buttons status is not set by their [tt]value[/tt].
HTML 4.01 said:
[tt]checked[/tt] [CI]
When the [tt]type[/tt] attribute has the value "radio" or "checkbox", this boolean attribute specifies that the button is on. User agents must ignore this attribute for other control types.
( HTML 4.01 | Forms | The [tt]INPUT[/tt] element | [tt]checked[/tt] )

Something like this :
Code:
[teal]<[/teal]input type[teal]=[/teal][green][i]"radio"[/i][/green] name[teal]=[/teal][green][i]"Text"[/i][/green] value[teal]=[/teal][green][i]"Fisier"[/i][/green] [teal]<?php[/teal] [b]if[/b] [teal]([/teal][navy]$controlvar[/navy][teal]==[/teal][green][i]'Fisier'[/i][/green][teal])[/teal] [b]echo[/b] [green][i]'checked="checked"'[/i][/green][teal];[/teal] [teal]?>[/teal] onClick[teal]=[/teal][green][i]"Val_text();Cont_pag2();"[/i][/green][teal]>[/teal]Check the one that was previously checked

[teal]<[/teal]input type[teal]=[/teal][green][i]"checkbox"[/i][/green] id[teal]=[/teal][green][i]"Navs0"[/i][/green] name[teal]=[/teal][green][i]"Navs0"[/i][/green] [teal]<?php[/teal] [b]if[/b] [teal]([/teal][navy]$controlvar[/navy][teal])[/teal] [b]echo[/b] [green][i]'checked="checked"'[/i][/green][teal];[/teal] [teal]?>[/teal] value[teal]=[/teal][green][i]"1"[/i][/green] onClick[teal]=[/teal][green][i]"Cont_pag5_3()"[/i][/green][teal]>[/teal]Check it [b]if[/b] it was previously checked[teal],[/teal] [b]if[/b] not leave it unchecked

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top