While using window.location the value entered in text box is not retained | Member | | Join Date: Oct 2008
Posts: 82
| |
Hi,
Here am trying to populate the page with new url, with the value that is being entered in the text box.
this is the php code called example.php -
<?
-
echo "<input type='text' name='text1' id='text1' />\n";
-
echo "<input type='button' name='button' onclick=\"return reload_page_with_value()\" />\n";
-
?>
-
the javascript code: -
function reload_page_with_value() {
-
var value=document.GetElementById('text1').value;
-
var url="example.php";
-
url=url+"?value=+"value;
-
window.location=url;
-
}
-
The problem here is, after the page is being reloaded with the value, the text entered in the textbox will not be available. Can somebody tell me the reason why this is happening and give the solution??
thanks
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,658
| | | re: While using window.location the value entered in text box is not retained Quote:
Originally Posted by sarega Can somebody tell me the reason why this is happening and give the solution?? getElementById() is written with a small "g", but why so complicated? just echo out the value in your server script using the default value attribute for <input> (<input ... value="default"/>). when you have a form, you don't need to reload the page with location.href, that's what the submit button is for (except for some special cases maybe).
| | Member | | Join Date: Oct 2008
Posts: 82
| | | re: While using window.location the value entered in text box is not retained
I want that value to be used for further processing. So how do i retrieve the value of value??
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,658
| | | re: While using window.location the value entered in text box is not retained
Javascript processing or PHP processing?
| | Member | | Join Date: Oct 2008
Posts: 82
| | | re: While using window.location the value entered in text box is not retained
I have to do php processing
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,658
| | | re: While using window.location the value entered in text box is not retained
submit the form. depending upon which submit button you use (you can have more than one submit type button in a form), the script can do different tasks with it.
| | Member | | Join Date: Oct 2008
Posts: 82
| | | re: While using window.location the value entered in text box is not retained
Actually the form is not complete with this textbox, there are more checkboxes in the form. After that i have a submit button
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,658
| | | re: While using window.location the value entered in text box is not retained
that doesn't matter, if you name this submit button (not the final one), say, "refresh" you can test for this value in the script and print the page with all the currently submitted values (and maybe some according processing))
like: - if (isset($_POST['refresh']))
-
{
-
// do some refreshing
-
// compute some other stuff
-
}
| | Member | | Join Date: Oct 2008
Posts: 82
| | | re: While using window.location the value entered in text box is not retained
I did not understand how to proceed?
| | Member | | Join Date: Oct 2008
Posts: 82
| | | re: While using window.location the value entered in text box is not retained
Cant we use textbox and checkboxes for window.location property??
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,658
| | | re: While using window.location the value entered in text box is not retained Quote:
Originally Posted by Mozilla Developer Center Returns a Location object, which contains information about the URL of the document and provides methods for changing that URL. You can also assign to this property to load another URL. window.location seems not the right place to me to handle form elements..... unless I've totally misunderstood you
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,658
| | | re: While using window.location the value entered in text box is not retained Quote:
Originally Posted by sarega I did not understand how to proceed? you can have multiple submit buttons in a form, so you can assign in your script a different function/processing to each of the buttons. the buttons can be distinguished by their name attributes. so if you put one submit button named "process" (just for example) and another one "refresh", then you can write (there's always only one submit button's value sent): - // HTML
-
<form action="...php" method="post" ...>
-
<!-- your form elements go here -->
-
<input type="submit" name="refresh" value="preview"/>
-
<input type="submit" name="process" value="send"/>
-
</form>
-
-
// PHP
-
if (isset($_POST['refresh']))
-
{
-
// preview and its processing code comes here
-
}
-
if (isset($_POST['process']))
-
{
-
// final processing code comes here
-
}
form elements which were not filled are either not present in $_POST or have an empty value (which you can check for with empty())
| | Member | | Join Date: Oct 2008
Posts: 82
| | | re: While using window.location the value entered in text box is not retained
There exists already another form which is pointing to another php file, in this case can i still use another form which points to a diff php file?
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,658
| | | re: While using window.location the value entered in text box is not retained
maybe a demonstrative html sample can clarify the matter for me.... I'm a bit lost now.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|