Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reload page when combi is changed 3

Status
Not open for further replies.

mych

Programmer
May 20, 2004
248
GB
Hi

I have the following which is triggered with an onChange on a combi box (id= aloc) in a form.

Code:
function AlocChange()
{
	window.navigate(location.href & "&A=" & getElementById('aloc').value)
}

I'm expecting the page to be reloaded but the URL to have an additional QueryString of &A= and then the new value of the changed combi box.

For some reason its not working.

Also... would I get several (e.g. &A=valuea&A=valueb&A=valuec) if the combi box is changed several times. Would the Request.QueryString take the first or last value of A?

Is there a better way... should I use session?

Any help aperetiated.
 
...For some reason its not working....
I'm not telepathic. Please tell us what it is not doing properly. What errors (if any) are being shown? What things have you tried to resolve your errors? What browser (and version) are you testing this in that gives you errors?

I suggest you install Firefox and Firebug (the extension). Then try and test your code for much better javascript feedback for errors etc.

...would I get several (e.g. &A=valuea&A=valueb&A=valuec) if the combi box is changed several times...
With your current code as it is, yes.

...Would the Request.QueryString take the first or last value of A?
Why don't you tell us? How long would it take you to find this out? I can't help you because I don't use ASP.

...Is there a better way... should I use session?
I would say yes... to both.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Yes... I think so.
What does that refer to? You are making very little sense.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
The 'yes I think' so was in response to Feherke question. You must excuse me as English is not my first language.
 
Hi

Code:
function AlocChange()
{
    [red]window.navigate[/red](location.href [green]&[/green] "&A=" [green]&[/green] [blue]getElementById[/blue]('aloc').value)
}
[ul]
[li][red]window.navigate[/red] - in good old JavaScript the [tt]window[/tt] object has no [tt]navigate()[/tt] method[/li]
[li][green]&[/green] - in JavaScript the [tt]&[/tt] operator means bitwise and, which applies to integers[/li]
[li][blue]getElementById[/blue] - in JavaScript the [tt]getElementById()[/tt] is a method of a node element, not a function or method of [tt]window[/tt] class[/li]
[/ul]
This is why I thought you accidentally posted an Explorer-only code, like VisualBasic.

Feherke.
 
is .navigate a prototype?

is the bigger picture missing from this code?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Hi

Hmm... Looks like Explorer and Opera indeed have a [tt]window.navigate()[/tt] native method.

Anyway, I would go with this :
Code:
function AlocChange()
{
    window.location.search+='&A='+document.getElementById('aloc').value)
}

Feherke.
 
cool never knew it had the method 'search' to change just the query string portion.

star for you!



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
The 'yes I think so' was in reply to Feherke. You must excuse me as English is not my first language...

Situation has improved but I am not able to assign the correct url. I have the following in the head of the asp.

Code:
function ChkURL()
{
	document.write(location.href)
}

function AlocChange()
{
	window.location.assign(document.location.href & "&A=" & document.getElementById("aloc"))
[red]window.navigate(document.location.href & "&A=" & document.getElementById("aloc"))   also works and give the same result[/red]
}

If I use the following line

Code:
<body onload="ChkURL()">

The correct CURRENT URL is displayed.

If I then revert to just <body>

The page displays as expected with no errors. I then select an new value from the aloc combi box and the url that the code assigns is...

(no errors)

what I'm hoping for is

[red]&A=NewChosenValueFromAlocCombi[/red]

Any help appreciated
 
Thanks all for suggestions.

window.location.search+='&A='+document.getElementById('aloc').value)

unfortunately did not work. Error given as object required.

I tried

window.location.assign(document.location.href [red]+[/red] "&A=" [red]+[/red] document.getElementById("aloc"))

can you tell I am more of a VB person
and the page went to

[object]

any ideas anyone?
 
that's because document.getElementById("aloc") is an object, you need the .value , to get the value of the object

try...
Code:
var myval = document.getElementById("aloc").value;

window.location.assign(document.location.href + "&A=" + myval);

unless "aloc" is not a standard input but aw dropdown,

then you would need to use the method for the selectedindex of the drop down to get the value.

what type of input field is this "aloc"




"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Code:
var myindex = document.getElementById("aloc").selectedIndex;
var myval = document.getElementById("aloc").options[myindex].value;
window.location.assign(document.location.href + "&A=" + myval);

I think that's the syntax you need, someone correct me if i'm wrong


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
1DMF

I think you have pinpointed my problem....

I have tried your suggestion and got an error related to expecting ;

But that aside the input is what I have called a combi or as you say dropdown.

I have now tried
Code:
	var OV = document.getElementById("aloc").selectedindex ;
	window.navigate(document.location.href + "&A=" + OV)

and got taken to


Mych
 
It needed to be selectedIndex....JS is case sencitive.

Unfortunately the url is now


or


or


etc depending if I selected the 2, 3 or 4th option from the dropdown

the parsed code for the dropdown is

Code:
<tr>
    <td Class="ViewRight">Allocation:&nbsp;</td>
    td Class="ViewLeft"><Select name= 'aloc' id = 'aloc' onChange='AlocChange()' >
        <option value='ALL' Selected>&nbsp;All Allocations&nbsp;</option>
        <option value='IDS'>&nbsp;IDS Allocation&nbsp;</option>
        <option value='ETECH'>&nbsp;Etech Allocation&nbsp;</option>
        <option value='OCC'>&nbsp;OCC Allocation&nbsp;</option>
    </select></td>
</tr>

I can feel we are almost there

Mych
 
that's why you need this line..
Code:
[b]var myval = document.getElementById("aloc").options[OV].value;[/b]
window.navigate(document.location.href + "&A=" + myval);

selectedIndex gives you the index of the array (which is what a select list is), you then you need to get either the .value or .text (which is the stuff between the option tag that is displayed in the dropdown).

hope that helps.


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
1DMF,

Many Many Thanks for the help. And to you Feherke

Final code was
Code:
function AlocChange()
{
	var OI = document.getElementById("aloc").selectedIndex ; [red]gives the Index[/red]
	var OV = document.getElementById("aloc").options(OI).value; [red]gives the Value[/red]
	window.navigate(document.location.href + "&A=" + OV)
}

Great... now forward and onward to the next challenge.
 
np.

lol ok it was round brackets not square :)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
As a final tweek I have used Feherke's excellent suggestion to just change the query part of the URL thus...

Code:
function AlocChange()
{
	var OI = document.getElementById("aloc").selectedIndex ;
	var OV = document.getElementById("aloc").options(OI).value;
	window.location.search='Mode=NI&Alc='+ OV
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top