By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,747 Members | 1,594 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,747 IT Pros & Developers. It's quick & easy.

How to populate the url with a value that is entered in text box without reloading

P: 82
I have a text box, when a user enters some value into the text box, that value has to be populated in the url and as well as the value entered in that text box has to be retained.
Expand|Select|Wrap|Line Numbers
  1. <?
  2. echo "<input type='text' id='text1' onchange=\"return_value()\" />
  3. ?>
Javascript code: am using ajax here
Expand|Select|Wrap|Line Numbers
  1. var xmlHttp;
  2. function return_value() {
  3. var x=document.getElementById('text1').value;
  4. xmlHttp = GetXmlHttpObject();
  5. if(xmlHttp == null) {
  6. alert("Your browser does not support ajax");
  7. return;
  8. }
  9. var url="ab.php";
  10. url=url+"?x="+x;
  12.  xmlHttp.send(null);
  13. xmlHttp.onreadystatechange = StateChanged;
  15. function StateChanged() {
  16. if(xmlHttp.readyState == 4) {
  17. document.getElementById('toRelease').value = xmlHttp.responseText;
  18. }
  19. }
ab.php file
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $y=$_GET['x'];
  3. echo $y;
  4. ?>
If i do this the value entered in the text box will be retained but i want that value to be populated in the url how to i do it??
Somebody plz help me
Jan 20 '09 #1
Share this Question
Share on Google+
4 Replies

Expert Mod 5K+
P: 8,639
without reloading, not at all. you can set a new URL but this will cause the browser to load this URL (any other thing wouldn't make any sense). from Javascript you can set the new URL with window.location.href.
Jan 20 '09 #2

Expert 5K+
P: 5,058

You could add it to the URL, however.

If your on and you do:
Expand|Select|Wrap|Line Numbers
  1. window.location.hash = "SomeString";
The URL would become

Other than that, you can not change the actual URL without redirecting to the new URL. It would be just stupid if that were possible. You could have your web pretend to be whatever web you wanted... like say, your bank's website.
Jan 20 '09 #3

P: 82
but by redirecting the url to new url ie reloading the value entered in text box will be lost...wht to do about it?
Jan 20 '09 #4

Expert Mod 5K+
P: 8,639
use PHP to populate the value attribute of your form element. for the <textarea> element to contain a default value, put the content between the tags.

Expand|Select|Wrap|Line Numbers
  1. // puts the text "write something in" in a input field
  2. <input type="text" value="write something in" ... />
  4. // writes "your story" in a <textarea>
  5. <textarea ...>your story</textarea>
Jan 20 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.