/    Sign up×
Community /Pin to ProfileBookmark

getElementById Sound Simple enough!

Hey all,

This is my first post on this site and it will not be the last I can tell you, I am going mad here as I know I have made this issue that I have working the past but for the life of me I cannot find the page with the code on.

The issue is:

I have a form field called productColour it has an id of productColour1 I am trying to reference the value of that field when the user clicks on an images button like so:

Input Field:
<input type=”text” name=”productColour” id=”productColour1″>

Button:
<input type=”button” name=”imagePopUp” value=”Images” onClick=”window.open(‘/admin/imageControl/index.cfm?productColour=document.getElementById(“productColour1″).value;’);”>

As you see the javascript is supposed to capture the value in the productColour field append it on to the end of the url query string.

I have tried everything I can think of and now I am off to find a brick wall to smash my head on to.

I hope that someone more knowledgeable than me could shed some light problem.

Mark ?

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@KorFeb 25.2011 — A referential value is not a string.

Wouldn't be better to call a function, instead?
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
&lt;meta http-equiv="Content-Style-Type" content="text/css"&gt;
&lt;meta http-equiv="Content-Script-Type" content="text/javascript"&gt;
&lt;script type="text/javascript"&gt;
function openWin(id){
window.open("/admin/imageControl/index.cfm?productColour=+document.getElementById(id).value+","");
}
&lt;/script&gt;
&lt;body&gt;
&lt;form action=""&gt;
&lt;input type="text" id="productColour1" value="boo"&gt;
&lt;input type="button" name="imagePopUp" value="Images" onclick="openWin('productColour1')"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@activecommerceauthorFeb 26.2011 — KOR

I like your thinking and it would make the code much neater however I have tried it and it does not work the value of the productcolour1 field is not being displayed just the javascript:

productColour=+document.getElementById(id).value+

this is the query sting displayed on the called page, I have tried this on the page and with a new document.

Mark
Copy linkTweet thisAlerts:
@KorFeb 27.2011 — Try
<i>
</i>window.open("/admin/imageControl/index.cfm?productColour="+document.getElementById(id).value+"","");
Copy linkTweet thisAlerts:
@activecommerceauthorFeb 28.2011 — Kor

thankyou you for your help, it's people like yourself that make the world a better place.

I have lost a whole day on this myself now I can get back on tracks

Your'a Star!!

Mark ?
Copy linkTweet thisAlerts:
@activecommerceauthorMar 10.2011 — Kor

I have been playing with the code you kindly sent over and I have been adding more functionality to it I do have one issue that I cannot work out and hoped you may know what to do. Can I add attributes like height and width of the opened window as you do in a normal window.open().

Regards

Mark
Copy linkTweet thisAlerts:
@KorMar 10.2011 — Kor

I have been playing with the code you kindly sent over and I have been adding more functionality to it I do have one issue that I cannot work out and hoped you may know what to do. Can I add attributes like height and width of the opened window as you do in a normal window.open().

Regards

Mark[/QUOTE]


Could be:

http://www.quirksmode.org/mobile/viewports.html

But it would be somehow unpleasant for the user. Most of the people use TABS now within the same browser. Modifying the window's size will modify the whole browser. Well, you can try
Copy linkTweet thisAlerts:
@activecommerceauthorMar 10.2011 — Sorry Kor I am not with you:

This is the final code the works fine:

(1) window.open("/admin/imageControl/index.cfm?productColour="+document.getElementById(id).value+"","");

What i wish to do is set the width and height on the window that will be opened e.g.

(2) onclick="window.open(("/admin/imageControl/index.cfm','testpopup','width=300,height200');

how can I enter the width and height info in the window.open (1) code.

Sorry If I am being think.

Regards

Mark Bryden
Copy linkTweet thisAlerts:
@KorMar 10.2011 — ah, sorry, I must have misunderstood your question

Do you want to add dynamically the values?
Copy linkTweet thisAlerts:
@activecommerceauthorMar 10.2011 — Kor

I want manually add the height and width attributes to the open window script

window.open("/admin/imageControl/index.cfm?productColour="+document.getElementById(id).value+"","");

Where in the above code can I manually put these variables

Width=300

height=400

Regards

Mark
×

Success!

Help @activecommerce spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...