473,799 Members | 3,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I pass a string as argument to onClick event handler in Javascript

2 New Member
I am facing difficulty when I was trying to pass a string as argument to OnClik Event Handler ,
Thanks for your suggestions in this regards
Jul 7 '07 #1
4 10168
gits
5,390 Recognized Expert Moderator Expert
hi ...

please post an example so that we may see what you already have ... and what the particular problem is ...

kind regards
Jul 7 '07 #2
kadkiran
2 New Member
thank you for ur response

actually I wan to send a string value as an argument by onClick event to event event handler program

I tried in this way

I extracted a value into a variable from a database table
<%
commodityCode = rstMenu("Commod ityCode")
%>

in the button onclick event

<input type="button" value="submit" name="btnSubmit " onClick="funSub mit(<%=commodit yCode%>)">

I hav sent the value to a javascript function,

<script language="javas cript">
function funSubmit(CCode )
{
alert(CCode)
}
</script>

when the button was clicked it is giving a script error " value undefined"

here I want to pass a string and I need to process it later on in my form
how to pass and access a string value from event's function as argument?
Jul 7 '07 #3
gits
5,390 Recognized Expert Moderator Expert
hi ...

<input type="button" value="submit" name="btnSubmit " onClick="funSub mit(<%=commodit yCode%>)">
add qoutes to it:

[HTML]<input type="button" value="submit" name="btnSubmit " onClick="funSub mit('\"' + <%=commodityCod e%> + '\"')">[/HTML]

kind regards ...

ps: this will not work! you should concat the quotes within the processing instruction or see below ... since i'm not very familiar with that you have to try for yourself ... ;)
Jul 7 '07 #4
gits
5,390 Recognized Expert Moderator Expert
ahhh ... wait ;)

you have to add the quotes before ... when creating the result ... here you have to add them so that commodityCode is a string with quotes ...

Expand|Select|Wrap|Line Numbers
  1. <%
  2. commodityCode = rstMenu("CommodityCode")
  3. %>
kind regards ...

ps: the upper solution will not work ... except see the ps in the upper post ...
Jul 7 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

13
26991
by: Al Franz | last post by:
Anyone understand how to pass parameters to a JavaScript. If anyone finds this easy to do maybe they could take a look at my short script on this page and show me how it needs to be changed. http://franz.org/java.htm Thanks for any help.
1
13017
by: TErnst | last post by:
Hello All.... What I am attempting to do is have a link/button on a page (testpopup.cfm) that opens a popup page (popupwindow.cfm). The popup page displays a resultset from a query and the selected record needs to be passed through a query string/URL parameter to the original calling page and will be available in the body onload event of the calling page. I open the popup window and display the query results, I then click on
10
2516
by: Sean Dockery | last post by:
I have the following HTML file that I've been using for testing... <html> <head> <script type="text/javascript"> <!-- function handleWindowLoad() { var items = ; for (var i = 0; i < 11; i++) { items = "item" + (i + 1);
2
2081
by: fusillo | last post by:
My code pass a value of a variable to the event handler's argument by means of eval statement here's: //statements setting evt for (var i=0; i<evt.periodi.length; i++){ //evt.periodi is an array of objs a=document.createElement("a"); a.onclick=eval('function (){ cancellaCal(' + evt.periodi.id_evt_cal
4
13569
by: sameergn | last post by:
Hi, I have an image in my HTML form which has onclick() handler. There is also a submit button and a text box. Whenever text box has focus and user presses enter, the onclick() event of image is fired with event.keyCode as undefined. I was expecting that the form would get submitted. I tried returning from onclick() handler if keyCode is null, but the
4
2386
by: simon | last post by:
hi, I would like to separate my javascript completely from my xhtml. in the end there should be only <script type="text/javascript" src="javalib.js"></script> in the head-tag to my javascript. Because I want to use some ajax-requests and other javascript-functions on my xhtml, I need to dynamically add event handlers to any possible dom-elements. All solutions I found so fare are for specific, pre-known
10
4083
by: Carlos Araya | last post by:
I have the following link on a web page <p class="menuitem"><a href="#" onclick="loadFragment('http://rivendellweb.net/fortress/home', 'index')" title="The Fortress Home">The Fortress Home</a></p>
4
2797
by: quoclinh | last post by:
Hi, I have the following function that works. It would create an input that would invoke a click event that call a javascript function: function createButton(text) { var btn = document.createElement('input'); btn.type = 'submit'; btn.value = text;
24
55243
by: =?Utf-8?B?U3dhcHB5?= | last post by:
Can anyone suggest me to pass more parameters other than two parameter for events like the following? Event: Onbutton_click(object sender, EventArgs e)" Event handler: button.Click += new EventHandler(Onbutton_click); I want to pass more information related that event. & want to use that
0
9541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10484
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
10251
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
9072
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...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
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
5463
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
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2938
bsmnconsultancy
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...

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.