JavaScript Help with display
In one of my previous posts here I got the information on what I had to do. Now I have a similar problem instead of using a button to do that I have 2 links that when clicked will take you to the same page but depending on the link clicked certain options are going to be grayed out.
I just dont know how to get started on this. If any one can show me a good place to start that would be greatly apreciated.
edouard89
Junior Poster in Training
53 posts since Feb 2007
Reputation Points: 10
Solved Threads: 2
Use the disabled attribute.
Start with the basic html portion of a form (named "order"):
<input type="text" id="quantity" disabled="disabled" />
Then, in JavaScript, you change the attribute to enable the field:
document.forms.order.quantity.disabled = false;
MidiMagic
Nearly a Senior Poster
3,319 posts since Jan 2007
Reputation Points: 730
Solved Threads: 182
I see, but how would it know which one has been clicked, because the two links both link to the same page and dependant of which is clicked the infromation will change.
edouard89
Junior Poster in Training
53 posts since Feb 2007
Reputation Points: 10
Solved Threads: 2
Fake the links with form input buttons:
<input type="button" id="quantity" name="ONE" onclick="javascript:menu1()" />
<input type="button" id="quantity" name="TWO" onclick="javascript:menu2()" />
Then use the javascript to first open the window, then enable the proper devices:
function menu1(){
theWindow = window.open('theurl.htm', 'theWin', '');
theWin.focus();
document.forms.order.quantity.disabled = false;
.
.
.
MidiMagic
Nearly a Senior Poster
3,319 posts since Jan 2007
Reputation Points: 730
Solved Threads: 182
I have an ASP page that uses
sub SetHoursMenu()
Dim period, empid, url, url2, url3, RS
sub_menu = "<div class=""menu"" id=""submenu-hours"">"
url = "Hours.asp"
url2 = "HourMod.asp"
url3 = "HourMod.asp"
period = request.QueryString("period")
if period <> "" then
url = url&"?period="&period
end if
if IsAdmin then
empid = request.QueryString("empid")
if empid = "" then
Set RS = Conn.Execute("SELECT * FROM users ORDER BY name")
empid = RS("id")
RS.Close
Set RS = nothing
end if
if InStr(url, "?") then
url = url&"&"
else
url = url&"?"
end if
url = url&"empid="&empid
url2 = url2&"?empid="&empid
url3 = url3&"?empid="&empid
end if
sub_menu = sub_menu&"<span>"&HyperLink(url, "<img src=""logs.gif"" width=""120"" height=""30"" id=""logsbutton"" />")&"</span>"
sub_menu = sub_menu&"<span onclick=""javascript:menu1()"">"&HyperLink(url2, "<img src=""img/companyhours.jpg"" width=""120"" height=""30"" id=""addbutton"" />")&"</span>"
sub_menu = sub_menu&"<span onclick=""javascript:menu2()"">"&HyperLink(url3, "<img src=""img/noncompanyhours.jpg"" width=""120"" height=""30"" id=""addbutton"" />")&"</span></div>"
end sub
To generate the URL for the links. My problem is that I dont know how to transfer that URL to the javascript function in order for it to display the page. Otherwise when the function opens a new window it tells me to relogin if it just use the "HourMod.asp" as the url. When the page loads the url is suposed to look something like this:
[HTML]http://....... edtemp/HourMod.asp?empid=1&sid=E3BCB8594C5F8EDF7A86CDD50266B6964196[/HTML]
And by the way is there a way of doing this without opening a new window?
Thanks,
edouard89
Junior Poster in Training
53 posts since Feb 2007
Reputation Points: 10
Solved Threads: 2
You could pass the url as a parameter.
<input type="button" id="quantity" name="ONE" onclick="javascript:menu1(url1.htm)" />
<input type="button" id="quantity" name="TWO" onclick="javascript:menu2(url2.htm)" />
Wouldn't it be easier to just have two versions of the page?
MidiMagic
Nearly a Senior Poster
3,319 posts since Jan 2007
Reputation Points: 730
Solved Threads: 182
Yes it would be a lot easier to make two pages but this is what I have to do. This is what I have done on this
response.Write "function menu1(txt)"
response.Write "{"
response.Write "theWindow=window.open(txt, 'theWin', '');"
response.Write "theWin.focus();"
response.Write "document.forms.Hours.nonCompany.disabled = true;"
response.Write "}"
response.Write "function menu2(txt)"
response.Write "{"
response.Write "theWindow=window.open(txt, 'theWin', '');"
response.Write "theWin.focus();"
response.Write "document.forms.Hours.nonCompany.disabled = false;"
response.Write "document.forms.Hours.nonCompany.checked = true;"
response.Write "}"
but when I use it with the buttons on the top
sub_menu = sub_menu&"<span onclick=""javascript:menu1(url2)""><img src=""img/companyhours.jpg"" width=""120"" height=""30"" id=""addbutton"" /></span>"
sub_menu = sub_menu&"<span onclick=""javascript:menu2(url3)""><img src=""img/noncompanyhours.jpg"" width=""120"" height=""30"" id=""addbutton"" /></span></div>"
It gives me an error saying that either url2 or url3 is undefined. I dont know weather this is because of the way I am using the the url2/url3 as parameters or something else.
I apreciate your help very much thank you.
edouard89
Junior Poster in Training
53 posts since Feb 2007
Reputation Points: 10
Solved Threads: 2
I think I know that my problem is in the fact that I am using a variable and not the actual URL, My question now is if its possible to use that as a parameter because of most of the function tutorials I have looked at always have an exact value and not a variable.
edouard89
Junior Poster in Training
53 posts since Feb 2007
Reputation Points: 10
Solved Threads: 2
The url should be in single quotes when passed as a parameter. It is text at that point.
What do you mean you "have to" do it that way? You got a nut for a boss?
MidiMagic
Nearly a Senior Poster
3,319 posts since Jan 2007
Reputation Points: 730
Solved Threads: 182
I am having trouble with the URL bieng used as a parameter. Is there a way that I can use javascript to get a value from vbscript and return that value from the vbscript to be used by the java script?
for example:
<span onclick=""javascript:menu1(VBFUNCTION HERE)"">
response.Write "function menu1(txt)"
response.Write "{"
response.Write "theWindow=window.open(txt, 'theWindow', '');"
.
.
.
The VBfunction would then return a value that would be used to open the new window. Or open the page in the same window?
edouard89
Junior Poster in Training
53 posts since Feb 2007
Reputation Points: 10
Solved Threads: 2
I was trying to see if I could get it to work by copying the URL from the page that open afterwards with this:
sub_menu = sub_menu&"<span onclick=""javascript:menu1('HoursMod.asp?empid=')"">"&HyperLink(url2, "<img src=""img/companyhours.jpg"" width=""120"" height=""30"" id=""addbutton"" />")&"</span>"
What happens is when I click this I open a new window but also continue to the proper page in the current window. The one that opens the new window cant find the page but if I add the URL from the page that continued to open in the same window it works. Also if i continue to click the links in the newly opened window they also work and they use the same window.
edouard89
Junior Poster in Training
53 posts since Feb 2007
Reputation Points: 10
Solved Threads: 2
Well I got it to work but I just left out the window pop-op thing and just made it so if one of the buttons is clicked it will activate the JS.
response.Write "<script language=""javascript"">"
response.Write "function menu1()"
response.Write "{"
response.Write "document.forms.hours.nonCompany.disabled = true;"
response.Write "document.forms.hours.nonCompany.checked = false;"
response.Write "document.forms.hours.nonCompany.value = 0;"
response.Write "}"
response.Write "function menu2()"
response.Write "{"
response.Write "document.forms.hours.nonCompany.disabled = true;"
response.Write "document.forms.hours.nonCompany.checked = true;"
response.Write "document.forms.hours.nonCompany.value = 1;"
response.Write "}"
response.Write "</script>"
Im just wondering now if there is a way that you can hide the checkbox using javascript (make it not visible to the viewer). If there isnt a way to do then thats ok.
edouard89
Junior Poster in Training
53 posts since Feb 2007
Reputation Points: 10
Solved Threads: 2