473,320 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

While using window.location the value entered in text box is not retained

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
Expand|Select|Wrap|Line Numbers
  1. <?
  2. echo "<input type='text' name='text1' id='text1' />\n";
  3. echo "<input type='button' name='button' onclick=\"return reload_page_with_value()\" />\n";
  4. ?>
  5.  
the javascript code:
Expand|Select|Wrap|Line Numbers
  1. function reload_page_with_value() {
  2.         var value=document.GetElementById('text1').value;
  3.         var url="example.php";
  4.         url=url+"?value=+"value;
  5.        window.location=url;
  6. }
  7.  
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
Jan 16 '09 #1
13 4611
Dormilich
8,658 Expert Mod 8TB
@sarega
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).
Jan 16 '09 #2
sarega
82
I want that value to be used for further processing. So how do i retrieve the value of value??
Jan 16 '09 #3
Dormilich
8,658 Expert Mod 8TB
Javascript processing or PHP processing?
Jan 16 '09 #4
sarega
82
I have to do php processing
Jan 16 '09 #5
Dormilich
8,658 Expert Mod 8TB
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.
Jan 16 '09 #6
sarega
82
Actually the form is not complete with this textbox, there are more checkboxes in the form. After that i have a submit button
Jan 16 '09 #7
Dormilich
8,658 Expert Mod 8TB
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:
Expand|Select|Wrap|Line Numbers
  1. if (isset($_POST['refresh']))
  2. {
  3.     // do some refreshing
  4.     // compute some other stuff
  5. }
Jan 16 '09 #8
sarega
82
I did not understand how to proceed?
Jan 19 '09 #9
sarega
82
Cant we use textbox and checkboxes for window.location property??
Jan 19 '09 #10
Dormilich
8,658 Expert Mod 8TB
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
Jan 19 '09 #11
Dormilich
8,658 Expert Mod 8TB
@sarega
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):
Expand|Select|Wrap|Line Numbers
  1. // HTML
  2. <form action="...php" method="post" ...>
  3. <!-- your form elements go here -->
  4.      <input type="submit" name="refresh" value="preview"/>
  5.      <input type="submit" name="process" value="send"/>
  6. </form>
  7.  
  8. // PHP
  9. if (isset($_POST['refresh']))
  10. {
  11.     // preview and its processing code comes here
  12. }
  13. if (isset($_POST['process']))
  14. {
  15.      // final processing code comes here
  16. }
form elements which were not filled are either not present in $_POST or have an empty value (which you can check for with empty())
Jan 19 '09 #12
sarega
82
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?
Jan 19 '09 #13
Dormilich
8,658 Expert Mod 8TB
maybe a demonstrative html sample can clarify the matter for me.... I'm a bit lost now.
Jan 19 '09 #14

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

Similar topics

3
by: J P Singh | last post by:
Hi Guys Wonder if someone can help me with this. I have a form where a user clicks a button which gives them a pop up windows to allow them to add the data. The user adds the data and click...
8
by: alanstew | last post by:
With the body tag calling out 'window onload', a function with a 'window.open' fails at the 'window.open' line. If I cut out the body tag, the function executes as normal. At first I thought it...
3
by: Richard | last post by:
I have a requirement to put a GDI style circle or rectangle border around the selected row of a datagrid/ It will overlap into the row above and below the selected row. Doing this in a the OnPaint...
8
by: johnsonholding | last post by:
Here is the code for a pop-up window that works in Firefox and not in IE - I get a java error or something, Here is the code : </script> <SCRIPT language="JavaScript"...
2
by: monomaniac21 | last post by:
Hi I know this isnt really a php question but can anyone tell me how you parse post variables to a popup window, here's my code so far, im trying to pass the value entered into a radio button: ...
3
by: anthonybrough | last post by:
I have an asp page that has a form to collect user data in a form. when the user clicks submit the input is validated. If any fields are not acceptable the user clicks on a button to go back to...
1
George Lft
by: George Lft | last post by:
ok, first of all, i built my register page using dreamweaver tool which the codes haven been out of control. Now i'm thinking that turning over everything - by using this another set of codes. And...
1
by: geetamadhavi | last post by:
Hi All, I have developed a php applciaiton where a new window is opening on checking the whether valid user orntot how to make that in same window after checking i have die(' not valid user ' ); i...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.