473,749 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

passing a javascript variable into an html form element

let me keep it clean, quick and simple.

I am passing a variable into another window and am reassigning the
value on the new page -

window.document .[formNameA].[varibaleNameA].value = opener.document .
..[formNameB].[varibaleNameB].value

and am wanting to then use this value within an element of a form on
the current page -

<form name="[formNameA]">

<input name="[variableNameA]" type="text">

</form>

but cannot seem to get the value passed to actually show up within the
input field of the form.

any thoughts or suggests?

t.i.a.


michael

Nov 23 '05 #1
3 3454
michael wrote:
let me keep it clean, quick and simple.
Good intention, but you've left out too much.

I am passing a variable into another window and am reassigning the
value on the new page -

window.document .[formNameA].[varibaleNameA].value = opener.document .
.[formNameB].[varibaleNameB].value
Presumably you are opening a popup from the window containing
'formNameB' and hoping to write the value of 'varibaleNameB' to the
popup's form named 'formNameA' with an element named 'varibaleNameA' .

Part of the problem is that the syntax is wrong, something like:

document.formNa meA.varibaleNam eA.value =
opener.document .formNameB.vari baleNameB.value ;
would do a better job - note the spelling of 'varibale' (sic).


and am wanting to then use this value within an element of a form on
the current page -

<form name="[formNameA]">

<input name="[variableNameA]" type="text">
Your call is to 'varibaleNameA' , note the difference in spelling.

</form>

but cannot seem to get the value passed to actually show up within the
input field of the form.
If you are using document.write to write the content of the popup, then
likely formNameA doesn't exist when you try to write to it.

any thoughts or suggests?


Showing the code (small test example) of what you are actually trying to
do would help.

Here's a small sample:
<script type="text/javascript">

function popForm()
{
var newWin = window.open('', 'New_Window','' );
newWin.document .write(
'<title>The new window</title>',
'<form name="formNameA " action="">',
'<input type="text" name="variableN ameA" value="',
document.formNa meB.variableNam eB.value,
'"></form>'
);
newWin.document .close();
}
</script>
<form action="" name="formNameB ">
<input type="text" name="variableN ameB" value="blah">
<input type="button" value="Pop form" onclick="popFor m()">
</form>
It would be better to pass a reference to the form from the onclick
event, but for the sake of the exercise I have kept the syntax close to
your original.

--
Rob
Nov 23 '05 #2
RobG wrote:
Good intention, but you've left out too much.
yeah, simple AND informative, not a good combination for me.

Presumably you are opening a popup from the window containing
'formNameB' and hoping to write the value of 'varibaleNameB' to the
popup's form named 'formNameA' with an element named 'varibaleNameA' .

Part of the problem is that the syntax is wrong, something like:

document.formNa meA.varibaleNam eA.value =
opener.document .formNameB.vari baleNameB.value ;
would do a better job - note the spelling of 'varibale' (sic).

at least my misspellings were consistent, eh? well, at least until I
called the variable to rename it...

for the sake of this exercise, I'm simply opening another window, but
the popup was the original intent.

Showing the code (small test example) of what you are actually trying to
do would help.

permission to email my test files ( four in all )?

It would be better to pass a reference to the form from the onclick
event, but for the sake of the exercise I have kept the syntax close to
your original.

--
Rob
uhm, yeah, back to your opening remark,
Good intention, but you've left out too much.


one of my objectives is to have the page(s) automatically move the
end-user through the pages after making their selections and or text
inputs. a tad more complication to the mix ( or what I like to call
confused state of uhm-dom ).

Rob,

I appreciate your taking the time and look forward to any future
responses. and apologies for not succinctly providing the necessary
details.

michael

Nov 23 '05 #3
michael wrote:
RobG wrote:
Good intention, but you've left out too much.
yeah, simple AND informative, not a good combination for me.
Presumably you are opening a popup from the window containing
'formNameB' and hoping to write the value of 'varibaleNameB' to the
popup's form named 'formNameA' with an element named 'varibaleNameA' .

Part of the problem is that the syntax is wrong, something like:

document.formNa meA.varibaleNam eA.value =
opener.document .formNameB.vari baleNameB.value ;
would do a better job - note the spelling of 'varibale' (sic).


at least my misspellings were consistent, eh? well, at least until I
called the variable to rename it...

for the sake of this exercise, I'm simply opening another window, but
the popup was the original intent.


If your script doesn't open the new window (AKA a popup), it can't
access it at all.

Showing the code (small test example) of what you are actually trying to
do would help.

permission to email my test files ( four in all )?


No, but there's no harm in posting up to say 100 lines of code that
display the issue. Often in developing a test case for posting you'll
discover a solution. If not, you have likely learned something anyway.

It would be better to pass a reference to the form from the onclick
event, but for the sake of the exercise I have kept the syntax close to
your original.
uhm, yeah, back to your opening remark,
> Good intention, but you've left out too much.


When an intrinsic event is fired you can get a reference to the element
that fired it using 'this', e.g.:
<input type="button" name="button-01" onclick="showNa me(this);">

<script type="text/javascript">
function showName(el)
{
// If the element has a name, show it
if (el.name) alert('The name is ' + el.name);

// If the element is in a form, say so
if (el.form) {
alert('I\'m in a form');
} else {
alert('Hangin\' ...');
}
}
</script>

Every element that is a form control has a 'form' property that is a
reference to the form the element is in. So once you have a reference
to the element with 'this' it is trivial to get a reference to the form.

Alternatively you could climb the DOM tree of the element's ancestors
until you get to a form element but it's not required (though that
strategy can be employed in other situations like getting a reference to
the table that a cell is in).
If an event is fired by a form's onsubmit handler:

<form name="formA" onsubmit="retur n doStuff(this);" ... >
Then doStuff can get a reference to the form:

function doStuff(theForm )
{
// theForm is a reference to formA
}


one of my objectives is to have the page(s) automatically move the
end-user through the pages after making their selections and or text
inputs. a tad more complication to the mix ( or what I like to call
confused state of uhm-dom ).


I take it that you hope to open windows to let the user make selections
that are then put into the form.

As a general strategy, that is fine but remember that not everyone has
JavaScript enabled so successful completion of the form should not be
dependent on JavaScript. The non-scripted version need not be pretty as
long as it is functional.

If this is for an intranet, then maybe you can ignore that advice.
--
Rob
Nov 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
42872
by: kie | last post by:
hello, when i create elements and want to assign events to them, i have realised that if the function assigned to that element has no parameters, then the parent node values can be attained. e.g. aTextBox=document.createElement('input'); aTextBox.onchange=calculateOneRow2;
12
6557
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the courses to pass the correct option value and then be displayed at the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html I am passing countries, products, and courses. The first two display
9
2170
by: Max | last post by:
I'm new with Javascript and can't seem to figure out what I'm doing wrong here as I'm not able to pass a simple variable to a function. In the head of doc I have: <script type="text/javascript"> function radioenable(value) { document.forms.search.elements.value.disabled=false;
5
2424
by: Steve | last post by:
Hi, I currently have a problem passing a variable value from one page to another. Once a form submit button is pressed java pops up a window and displays some information. The problem being is variables value needs to be passed from the main page to this popup window ... but it isn't. why? the submit button one the PHP page is
0
8996
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
9566
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...
0
9388
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8256
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
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
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...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
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
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.