473,811 Members | 2,565 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form querystring manipulation.

6 New Member
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:
http://192.168.2.16/Seznam.php?IdR= 1
http://192.168.2.16/Seznam.php?IdR= 1&IdM=101
These two are correct urls, region 1 and city 1 in region 1.

If you now change the region you will get this.
http://192.168.2.16/Seznam.php?IdR= 4&IdM=101
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
  6.  
  7.    $Regija = Zavaruj($_GET['IdR']);
  8.    $Mesto = Zavaruj($_GET['IdM']);
  9.    // $Mesto_2 = substr($Mesto,0,1);
  10.  
  11.    $Poizvedba_Regije = mysql_query("SELECT * FROM Regije ORDER BY Id");
  12.  
  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.    }
  19.  
  20.    ?>
  21.    </select>
  22.    <?PHP
  23.  
  24.    if (!$Regija)
  25.    {
  26.       echo "</fieldset></form>";
  27.    }
  28.  
  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
  35.  
  36.       $Poizvedba_Mesta = mysql_query("SELECT * FROM Mesta WHERE Id_Regije = '$Regija' ORDER BY Id");
  37.  
  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.       }
  44.  
  45.       ?>
  46.       </select>
  47.       </fieldset>
  48.       </form>
  49.       <?PHP
  50.    }
  51.  
Sep 25 '09 #1
11 3672
Dormilich
8,658 Recognized Expert Moderator Expert
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
AnonG
6 New Member
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
Dormilich
8,658 Recognized Expert Moderator Expert
@AnonG
a hidden field is completely useless.

@AnonG
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();
  4.  
  5. S2:
  6. form.submit();
@AnonG
not a problem for AJAX, merely a matter of you JS skills.
Sep 25 '09 #4
AnonG
6 New Member
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>
  7.  
I have tried adding this reset() to select fields and to option fields.. nothing worked.
Sep 25 '09 #5
Dormilich
8,658 Recognized Expert Moderator Expert
I thought of
Expand|Select|Wrap|Line Numbers
  1. document.forms.IdM.value = 0;
Sep 25 '09 #6
AnonG
6 New Member
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
Dormilich
8,658 Recognized Expert Moderator Expert
@AnonG
there should nothing visible happen. does the URL be right now?
Sep 25 '09 #8
AnonG
6 New Member
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>
  7.  
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() }">
  2.  
If I add it like that nothing happens when I change regions in the first select form.
Sep 25 '09 #9
Dormilich
8,658 Recognized Expert Moderator Expert
can you give me a link to the page, so that i can see for myself?
Sep 25 '09 #10

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

Similar topics

5
2581
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 called "txtName" if i click the submit button for example the asp page reads the content of this txtName as Request.Form("txtName") I want to achieve that the asp form is accessed through a URL where i can pass the value of txtName without going to the page of the form and clicking
10
3596
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 works until I added the function checkIt() to validate which radio button was clicked and what was in a textfield. The form is an attendance checking page for a cyber charter school. What I'm trying to accomplish is that if a parent marks the student present, there should not be anything in the...
4
1030
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 sorting. The problem I have is that at the moment, the user enters search criteria into the search box and clicks the search image button to trigger the search. I now need the arrows to also submit the search - not the end of the world, I can make them image buttons, but I have no idea how to...
7
1929
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" action="/includes/mypage2.asp?subtype=MyType&amp;ecd=1&amp;eid=97702"> ....Do some stuff
5
7682
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 redirect the user to another page, passing these parameters, but not as a querystring. Any help would be gratefully received.
2
1287
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 them. So here's the problem: when I perform a search for the first time, everything works perfectly. If I make any changes to the controls in the form and resubmit the page, nothing changes. That is, viewing the querystring, not a single value is altered despite my doing so in the form itself....
6
1820
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 table i have the fields <td><input id="email" type="text" runat="server" /></tdand a submit button. In the asp.net page, how do i get the values of the posted form ? Thanks
7
9663
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 support "toString", or any JavaScript string operation on parameters not passed. Example: Make a TST.asp and post to it as TST.asp?STATE=TEST <%@ Language=JavaScript %> <%
0
10955
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 function when I kept having to change values of the QueryString and remove some, add some, etc., etc.. It takes four (4) parameters: oldUrl = the current QueryString you would like manipulated qsName = the name of the QueryField you would like to modify/remove/add newValue = the new value you...
0
9731
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10405
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10136
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5556
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4342
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3871
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3020
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.