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. -
<form method="get" action="Seznam.php" id="Spremeni">
-
<fieldset>
-
<select class="Polje" name="IdR" onchange="if(this.options[this.selectedIndex].value != -1){ forms['Spremeni'].submit() }">
-
<option value="0">Izberi Regijo</option>
-
<?PHP
-
-
$Regija = Zavaruj($_GET['IdR']);
-
$Mesto = Zavaruj($_GET['IdM']);
-
// $Mesto_2 = substr($Mesto,0,1);
-
-
$Poizvedba_Regije = mysql_query("SELECT * FROM Regije ORDER BY Id");
-
-
while ($Izpis_Regij = mysql_fetch_assoc($Poizvedba_Regije))
-
{
-
?>
-
<option value="<?PHP echo $Izpis_Regij['Id'] ?>" <?PHP if ($Regija == $Izpis_Regij['Id']) echo "selected=\"selected\""; ?>><?PHP echo $Izpis_Regij['Ime'] ?></option>
-
<?PHP
-
}
-
-
?>
-
</select>
-
<?PHP
-
-
if (!$Regija)
-
{
-
echo "</fieldset></form>";
-
}
-
-
if ($Regija)
-
{
-
?>
-
<select class="Polje" name="IdM" onchange="if(this.options[this.selectedIndex].value != -1){ forms['Spremeni'].submit() }">
-
<option value="0">Izberi Mesto</option>
-
<?PHP
-
-
$Poizvedba_Mesta = mysql_query("SELECT * FROM Mesta WHERE Id_Regije = '$Regija' ORDER BY Id");
-
-
while ($Izpis_Mest = mysql_fetch_assoc($Poizvedba_Mesta))
-
{
-
?>
-
<option value="<?PHP echo $Izpis_Mest['Id'] ?>" <?PHP if ($Mesto == $Izpis_Mest['Id']) echo "selected=\"selected\""; ?>><?PHP echo $Izpis_Mest['Ime'] ?></option>
-
<?PHP
-
}
-
-
?>
-
</select>
-
</fieldset>
-
</form>
-
<?PHP
-
}
-
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.
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.
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: - S1:
-
S2.value = default;
-
form.submit();
-
-
S2:
-
form.submit();
@AnonG
not a problem for AJAX, merely a matter of you JS skills.
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? -
<script type="Javascript">
-
function reset()
-
{
-
document.forms["Spremeni"].elements["IdM"].selectedIndex = 0;
-
}
-
</script>
-
I have tried adding this reset() to select fields and to option fields.. nothing worked.
Dormilich 8,658
Recognized Expert Moderator Expert
I thought of - document.forms.IdM.value = 0;
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.
Dormilich 8,658
Recognized Expert Moderator Expert @AnonG
there should nothing visible happen. does the URL be right now?
I mean, I created a function with what you wrote in it. -
<script type="Javascript">
-
function reset()
-
{
-
document.forms.IdM.value = 0;
-
}
-
</script>
-
And then I included it into this. -
<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.
Dormilich 8,658
Recognized Expert Moderator Expert
can you give me a link to the page, so that i can see for myself?
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 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
|
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...
|
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...
|
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&ecd=1&eid=97702">
....Do some stuff
|
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.
| |
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....
|
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
|
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 %>
<%
|
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...
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |