472,348 Members | 1,255 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Form querystring manipulation.

Hi all,

I'm trying to create a simple navigation script. It allows you to select a region. Once region is selected another list opens up and you can select a city within that region. It all works fine, you can change cities freely and url updates correctly. BUT if you have a city selected and want to re-select the region, the city id stays in the url which messes up my page.

Some examples:
These two are correct urls, region 1 and city 1 in region 1.

If you now change the region you will get this.
Which means region 4 and city 1 in region 1. It should set IdM (city id) to 0 or remove it completely.

Any ideas?

Here's the code I'm using.
Expand|Select|Wrap|Line Numbers
  1.    <form method="get" action="Seznam.php" id="Spremeni">
  2.    <fieldset>
  3.    <select class="Polje" name="IdR" onchange="if(this.options[this.selectedIndex].value != -1){ forms['Spremeni'].submit() }">
  4.    <option value="0">Izberi Regijo</option>
  5.    <?PHP
  7.    $Regija = Zavaruj($_GET['IdR']);
  8.    $Mesto = Zavaruj($_GET['IdM']);
  9.    // $Mesto_2 = substr($Mesto,0,1);
  11.    $Poizvedba_Regije = mysql_query("SELECT * FROM Regije ORDER BY Id");
  13.    while ($Izpis_Regij = mysql_fetch_assoc($Poizvedba_Regije))
  14.    {
  15.       ?>
  16.       <option value="<?PHP echo $Izpis_Regij['Id'] ?>" <?PHP if ($Regija == $Izpis_Regij['Id']) echo "selected=\"selected\""; ?>><?PHP echo $Izpis_Regij['Ime'] ?></option>
  17.       <?PHP
  18.    }
  20.    ?>
  21.    </select>
  22.    <?PHP
  24.    if (!$Regija)
  25.    {
  26.       echo "</fieldset></form>";
  27.    }
  29.    if ($Regija)
  30.    {
  31.       ?>
  32.       <select class="Polje" name="IdM" onchange="if(this.options[this.selectedIndex].value != -1){ forms['Spremeni'].submit() }">
  33.       <option value="0">Izberi Mesto</option>
  34.       <?PHP
  36.       $Poizvedba_Mesta = mysql_query("SELECT * FROM Mesta WHERE Id_Regije = '$Regija' ORDER BY Id");
  38.       while ($Izpis_Mest = mysql_fetch_assoc($Poizvedba_Mesta))
  39.       {
  40.          ?>
  41.          <option value="<?PHP echo $Izpis_Mest['Id'] ?>" <?PHP if ($Mesto == $Izpis_Mest['Id']) echo "selected=\"selected\""; ?>><?PHP echo $Izpis_Mest['Ime'] ?></option>
  42.          <?PHP
  43.       }
  45.       ?>
  46.       </select>
  47.       </fieldset>
  48.       </form>
  49.       <?PHP
  50.    }
Sep 25 '09 #1
11 3477
8,658 Expert Mod 8TB
before you submit the form from the first select, simply reset the value of the second select.

you could improve your code further by using AJAX, so that you donít need to reload the page each time.
Sep 25 '09 #2
If I add a hidden input with name IdM then I get this: IdR=1&IdM=0&IdM=whatever it was before.

I think I don't understand exactly what you mean.

About ajax, I need to refresh page each time because that way all links get new paths. Sort of like categories / subcategories on a webstore page.
Sep 25 '09 #3
8,658 Expert Mod 8TB
a hidden field is completely useless.

well, I kind of understand thatÖ

ok, first you need to understand, how your form works. you have 2 form fields (2x <select> (Iíll refer to it as S1 and S2))
if you call form.submit() (either in S1 or S2) the browser checks every form field and makes a name-value pair for each and transforms that into an URL (in your case).

now the idea is that when you call submit() from S1, before you actually call it, you need to reset the current name-value pair of S2 (i.e. only the value, because the name is not changed)

expressed as pseudo code:
Expand|Select|Wrap|Line Numbers
  1. S1:
  2. S2.value = default;
  3. form.submit();
  5. S2:
  6. form.submit();
not a problem for AJAX, merely a matter of you JS skills.
Sep 25 '09 #4
I have no knowledge of JS. I've been googling for hours now and I didn't find anything useful.

Am I going into the right direction?

Expand|Select|Wrap|Line Numbers
  1. <script type="Javascript">
  2. function reset()
  3. {
  4. document.forms["Spremeni"].elements["IdM"].selectedIndex = 0;
  5. }
  6. </script>
I have tried adding this reset() to select fields and to option fields.. nothing worked.
Sep 25 '09 #5
8,658 Expert Mod 8TB
I thought of
Expand|Select|Wrap|Line Numbers
  1. document.forms.IdM.value = 0;
Sep 25 '09 #6
Were should I put that? I've tried adding it into select onchange"" but then I can't change region. Nothing happens when I click it.
Sep 25 '09 #7
8,658 Expert Mod 8TB
there should nothing visible happen. does the URL be right now?
Sep 25 '09 #8
I mean, I created a function with what you wrote in it.

Expand|Select|Wrap|Line Numbers
  1. <script type="Javascript">
  2. function reset()
  3. {
  4. document.forms.IdM.value = 0;
  5. }
  6. </script>
And then I included it into this.

Expand|Select|Wrap|Line Numbers
  1.  <select class="Polje" name="IdR" onchange="if(this.options[this.selectedIndex].value != -1){ reset() forms['Spremeni'].submit() }">
If I add it like that nothing happens when I change regions in the first select form.
Sep 25 '09 #9
8,658 Expert Mod 8TB
can you give me a link to the page, so that i can see for myself?
Sep 25 '09 #10
8,658 Expert Mod 8TB
the interesting point is that it works every second time...
Sep 25 '09 #11
Yep. Been like that since day one. I kinda need to get it to work every time not every second, hehe. But my lack of JS skills doesn't help at all. :)
Sep 25 '09 #12

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

Similar topics

by: momo | last post by:
Hello Newsgroup, I want to pass a Request.Form variable to an ASP form, through the url for example lets say i have a form with a textfiled...
by: Steve Benson | last post by:
Our regular programmer moved on. I'm almost clueless in Javascript/ASP and got the job of adapting existing code. In the page below, everything...
by: Rob Meade | last post by:
Hi all, I have a page which displays some database results. On each column heading I have 2 images, an arrow up, and arrow down for my data...
by: eric.goforth | last post by:
Hello, I'm working with a classic asp page that calls another classic asp page. The html in my calling page looks like: <form method="post"...
by: Nirmal Singh | last post by:
I am a newbie trying to learn ASP.net 2.0. I want to retrieve the QueryString and process it to produce some parameters. I then want to...
by: Roshawn | last post by:
Hi, On my asp.net page I have an html form. I've set runat attribute to server and filled it with server controls. All settings are as I like...
by: Carlo | last post by:
I have an html form that posts onto an asp.net page (vs2005). The form header is as follows: <form action="thankyou.aspx" method="post">. In a...
by: =?Utf-8?B?QVRT?= | last post by:
HOWTO Make CStr for JavaScript on ASP w/ Request.Form and QueryString In ASP, Request.Form and Request.QueryString return objects that do not...
by: sirjohnofthewest | last post by:
This function will give you 100% control over the QueryString -- perfect for programmers who use QueryString manipulation a lot. I wrote this...
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

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.