Is it possible to affect value to an input tag without having to redraw it?
Good exemple(What I want to do)
document.getElementById('Titre').Value = $myrow2["Titre"];
Bad exemple(What I don't want to do)
printf("<input name="Titre" type="text" value="%s">",$myrow2["Titre"]);Is it possible to affect value to an input tag without having to redraw it?
by redraw I meant not use a printf or a echo but only assign the value to the input value property.
Also, how can i get the selected value of a select list(or value list or dropdownlist, I'm not sure how to call it)?php all happens Server Side, so if you want to change values in a form without re-loading it from the server, then you need a client side language such as javascript. There is a Cliet Side Forum (<!-- m --><a class="postlink" href="http://www.htmlforums.com/forumdisplay.php?s=&forumid=6">http://www.htmlforums.com/forumdisplay.php?s=&forumid=6</a><!-- m -->) here, and you can find most of what you want at <!-- w --><a class="postlink" href="http://www.hotscripts.com">www.hotscripts.com</a><!-- w -->. Their forms section can be found here (<!-- m --><a class="postlink" href="http://www.hotscripts.com/JavaScript/Scripts_and_Programs/Forms/index.html">http://www.hotscripts.com/JavaScript/Sc ... index.html</a><!-- m -->).Ok, I just understood that what I wanted to do is impossible and I change my code to make this work. now I have a problem getting the value of the selected item of the list.
I tried assigning it to a var, but I can't manage to make it work.
I look like this after a lot of tries(I'm pretty sure it's not supposed to work exactly like this but it give an idea of what I'm triing to do)
$Section = document.getElementById("ListeSection").selecteditem.options.value;Make a javascript function like this:
function get_selected(selected)
{
var item = selected.options[selected.selectedIndex].value;
}
and call it like this:
get_selected('document.formname.fieldname')
The value of whatever is selected will be in the item variable, and you can do whatever with it.
simply replace your form name in for "formname" and the name of your select box in for "fieldname"
if you don't want to do it as a function, you can do it inline like this:
<script language="JavaScript" type="text/JavaScript">
var item = document.formname.fieldname.options[document.formname.fieldname.selectedIndex].value;
</script>
I noticed that you are trying to assign it to $Section. That looks like the syntax for a php variable. AFAIK you can't use javascript to assign data to a php variable.
in Javascript, a variable is set like this:
var ID = 1;
Then used like this:
if(ID == 1)
{
do something
}
EDIT: Someone should probably move this to client side scripting?Someone should not because I DONT WANT TO USE JAVASCRIPT.
I know how to do this in javascript, but i'm asking how can i do this in PHP.AFAIK: php all happens Server Side, so if you want to change values in a form without re-loading it from the server, then you need a client side language such as javascript
Also, "$Section = document.getElementById("ListeSection").selecteditem.options.value;" looks like javascript, except for the $ variable notation. I couldn't find anything in the php manual (<!-- m --><a class="postlink" href="http://www.php.net/manual/en/">http://www.php.net/manual/en/</a><!-- m -->) either that suggested that document.getElementById("ListeSection").selecteditem.options.value; was valid php. It looks like javascript.
AFAIK there is no way to do what you want from server side. In order for php to see what is in one of the form fields, the info from that field needs to be passed to the server (where php does it's work). If the form is not submitted yet, then the data is ONLY on the user's computer (client side).Ok so there is no way to take whats inside the fields exept if I pass them in the adress bar and get them there?There is no way to get the values unless the form is submitted. They don't, however, have to be passed through the address bar. In the form tag, set the method to POST, and set the action to whatever php file you will be using to handle the data.
Then in the php file, you can access the data from the form by using $_POST['fieldname'] where fieldname is the name of the field that had the data in it that you want. You can use $_POST['fieldname'] as the variable, OR you can put it into a local variable like this:
$Section = $_POST['fieldname']Thanks, you helped me a lot.
And one last question(I hope) how can I make the page refresh when I select an item from my list?
(Something that do the same thing as the property AutoPostBack in asp.net)Well, I don't know much about AutoPostBack, so I'm really that sure.
I read a little bit, and it SOUNDS like it submits the formfield to the current page. I'm not sure how to submit a just one field, but you can submit your whole form when the dropdown changes.
If the form consists of only the one select field, it'd be pretty much the same.
make the select tag like this:
<select name="driver_emails" onchange="document.formname.submit();">
Then, when the user changes the dropdown menu, it will submit the form. This really only works for what you are wanting, if the action="" is set to the current page. Otherwise it will submit the data to whatever page you specified.I tried that but I get this error: Error: document.LstSection has no properties
Any idea why?
Here is the form portion of my code:
<form name="Photos" method="post" action="<?php
printf("%s?ListeSection=%s",$_SERVER['PHP_SELF'],$_POST["ListeSection"]);?>">
<!-- Forme uniquement pour la liste -->
<form name="LstSection" method="post" action="<?php
printf("%s?ListeSection=%s",$_SERVER['PHP_SELF'],$_POST["ListeSection"]);?>">
<label>Sé—ÂÂ榚ctionner la section ?modifier :</label>
<select name="ListeSection" onchange="document.LstSection.submit();">
<?php
if($myrow = mysql_fetch_array($result))
{
for($iCtr=1; $iCtr <=$Num; $iCtr++)
{
printf("<option>%s</option>",$myrow["Section"]);
$myrow = mysql_fetch_array($result);
}
}
?>
</select>
</form>
<p></p>
<?php
AfficherInfos();
?>
<input type="Submit" name="Submit" value="Enregistrer" onClick="<?php $Submit = true; ?>">
</form>
Good exemple(What I want to do)
document.getElementById('Titre').Value = $myrow2["Titre"];
Bad exemple(What I don't want to do)
printf("<input name="Titre" type="text" value="%s">",$myrow2["Titre"]);Is it possible to affect value to an input tag without having to redraw it?
by redraw I meant not use a printf or a echo but only assign the value to the input value property.
Also, how can i get the selected value of a select list(or value list or dropdownlist, I'm not sure how to call it)?php all happens Server Side, so if you want to change values in a form without re-loading it from the server, then you need a client side language such as javascript. There is a Cliet Side Forum (<!-- m --><a class="postlink" href="http://www.htmlforums.com/forumdisplay.php?s=&forumid=6">http://www.htmlforums.com/forumdisplay.php?s=&forumid=6</a><!-- m -->) here, and you can find most of what you want at <!-- w --><a class="postlink" href="http://www.hotscripts.com">www.hotscripts.com</a><!-- w -->. Their forms section can be found here (<!-- m --><a class="postlink" href="http://www.hotscripts.com/JavaScript/Scripts_and_Programs/Forms/index.html">http://www.hotscripts.com/JavaScript/Sc ... index.html</a><!-- m -->).Ok, I just understood that what I wanted to do is impossible and I change my code to make this work. now I have a problem getting the value of the selected item of the list.
I tried assigning it to a var, but I can't manage to make it work.
I look like this after a lot of tries(I'm pretty sure it's not supposed to work exactly like this but it give an idea of what I'm triing to do)
$Section = document.getElementById("ListeSection").selecteditem.options.value;Make a javascript function like this:
function get_selected(selected)
{
var item = selected.options[selected.selectedIndex].value;
}
and call it like this:
get_selected('document.formname.fieldname')
The value of whatever is selected will be in the item variable, and you can do whatever with it.
simply replace your form name in for "formname" and the name of your select box in for "fieldname"
if you don't want to do it as a function, you can do it inline like this:
<script language="JavaScript" type="text/JavaScript">
var item = document.formname.fieldname.options[document.formname.fieldname.selectedIndex].value;
</script>
I noticed that you are trying to assign it to $Section. That looks like the syntax for a php variable. AFAIK you can't use javascript to assign data to a php variable.
in Javascript, a variable is set like this:
var ID = 1;
Then used like this:
if(ID == 1)
{
do something
}
EDIT: Someone should probably move this to client side scripting?Someone should not because I DONT WANT TO USE JAVASCRIPT.
I know how to do this in javascript, but i'm asking how can i do this in PHP.AFAIK: php all happens Server Side, so if you want to change values in a form without re-loading it from the server, then you need a client side language such as javascript
Also, "$Section = document.getElementById("ListeSection").selecteditem.options.value;" looks like javascript, except for the $ variable notation. I couldn't find anything in the php manual (<!-- m --><a class="postlink" href="http://www.php.net/manual/en/">http://www.php.net/manual/en/</a><!-- m -->) either that suggested that document.getElementById("ListeSection").selecteditem.options.value; was valid php. It looks like javascript.
AFAIK there is no way to do what you want from server side. In order for php to see what is in one of the form fields, the info from that field needs to be passed to the server (where php does it's work). If the form is not submitted yet, then the data is ONLY on the user's computer (client side).Ok so there is no way to take whats inside the fields exept if I pass them in the adress bar and get them there?There is no way to get the values unless the form is submitted. They don't, however, have to be passed through the address bar. In the form tag, set the method to POST, and set the action to whatever php file you will be using to handle the data.
Then in the php file, you can access the data from the form by using $_POST['fieldname'] where fieldname is the name of the field that had the data in it that you want. You can use $_POST['fieldname'] as the variable, OR you can put it into a local variable like this:
$Section = $_POST['fieldname']Thanks, you helped me a lot.
And one last question(I hope) how can I make the page refresh when I select an item from my list?
(Something that do the same thing as the property AutoPostBack in asp.net)Well, I don't know much about AutoPostBack, so I'm really that sure.
I read a little bit, and it SOUNDS like it submits the formfield to the current page. I'm not sure how to submit a just one field, but you can submit your whole form when the dropdown changes.
If the form consists of only the one select field, it'd be pretty much the same.
make the select tag like this:
<select name="driver_emails" onchange="document.formname.submit();">
Then, when the user changes the dropdown menu, it will submit the form. This really only works for what you are wanting, if the action="" is set to the current page. Otherwise it will submit the data to whatever page you specified.I tried that but I get this error: Error: document.LstSection has no properties
Any idea why?
Here is the form portion of my code:
<form name="Photos" method="post" action="<?php
printf("%s?ListeSection=%s",$_SERVER['PHP_SELF'],$_POST["ListeSection"]);?>">
<!-- Forme uniquement pour la liste -->
<form name="LstSection" method="post" action="<?php
printf("%s?ListeSection=%s",$_SERVER['PHP_SELF'],$_POST["ListeSection"]);?>">
<label>Sé—ÂÂ榚ctionner la section ?modifier :</label>
<select name="ListeSection" onchange="document.LstSection.submit();">
<?php
if($myrow = mysql_fetch_array($result))
{
for($iCtr=1; $iCtr <=$Num; $iCtr++)
{
printf("<option>%s</option>",$myrow["Section"]);
$myrow = mysql_fetch_array($result);
}
}
?>
</select>
</form>
<p></p>
<?php
AfficherInfos();
?>
<input type="Submit" name="Submit" value="Enregistrer" onClick="<?php $Submit = true; ?>">
</form>