By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,358 Members | 2,957 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,358 IT Pros & Developers. It's quick & easy.

Some help on passing a parameter in text HTML(javascript)?

100+
P: 200
Hi, I need help please

I usually code in coldfusion but now i want to create 2 text html files where i
pass a parameter on href?

This normally works in coldfusion!

Page1
[HTML]<a href="test.htm?test=100','','height=300,width=300" >[/HTML]

Page2
[HTML]<html>
<head>
<param name="test" value=""/>
</head>
<body>
<cfoutput>
#test#
</cfoutput>
</body>
</html>[/HTML]

It displays #test# but in the url i can see the value it's passing but the second
page does not pick it up!

Assist"Without some kind of server-side processing (PHP, ColdFusion, etc.) or
some fancy JavaScript, you aren't going to be able to display a URL
variable. Raw HTML can't do that"

Does anyone have an example of some javascript/ or other that can do it?

Regards
Jan 10 '08 #1
Share this Question
Share on Google+
9 Replies


gits
Expert Mod 5K+
P: 5,333
hi ...

you could call the following function onload that returns you the url-params as a js-object:

Expand|Select|Wrap|Line Numbers
  1. function get_url_params() {
  2.     var params = {};
  3.     var q_str  = location.search.match(/([^&?]+)/g);
  4.  
  5.     for (var i = 0, param; param = q_str[i]; i++) {
  6.         var key = param.match(/^([^=]+)/)[1];
  7.         var val = param.match(/([^=]+)$/)[1];
  8.  
  9.         params[key] = val;
  10.     }
  11.  
  12.     return params;
  13. }
  14.  
now you could use:

[HTML]<body onload="var params = get_url_params();">[/HTML]
and params is now a global variable that stores the params, and you may retrieve them from javascript with: params.param_name

kind regards
Jan 10 '08 #2

100+
P: 200
Thanks for the help, I'm really lost - Please Assist!

Page1:
[HTML]<html>
<head>

<script type="text/javascript">
function get_url_params() {
var params = {};
var q_str = location.search.match(/([^&?]+)/g);

for (var i = 0, param; param = q_str[i]; i++) {
var key = param.match(/^([^=]+)/)[1];
var val = param.match(/([^=]+)$/)[1];

params[key] = val;
}

return params;
}
</script>
</head>
<body>
<form action="ajax.htm">
<body onload="var params = get_url_params();">
<form action="ajax.htm">
params.param_name
document.params.param_name.value
#params.param_name#
<A HREF='ajax.htm?test=100'>Click here</A>
</form>
</body>
</html>[/HTML]

Page2:
[HTML]<html>
<head>

<script type="text/javascript">
function get_url_params() {
var params = {};
var q_str = location.search.match(/([^&?]+)/g);

for (var i = 0, param; param = q_str[i]; i++) {
var key = param.match(/^([^=]+)/)[1];
var val = param.match(/([^=]+)$/)[1];

params[key] = val;
}

return params;
}
</script>
</head>
<body onload="var params = get_url_params();">
<form action="ajax.htm">
params.param_name
document.params.param_name.value
#params.param_name#
<input type="text" name="test">
</form>
</body>
</html>[/HTML]
Jan 10 '08 #3

gits
Expert Mod 5K+
P: 5,333
what do you want to do? display the value of the param? the params-variable holds the url-params onload ... now we could further use it in further javascript-code ...

kind regards
Jan 10 '08 #4

100+
P: 200
Hi: Thank You very much but the idea did not come off as what i thought!
I found another script but my initial problem is not fixed!
script:
[HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
;(function(){
var field='Something', //set the name of the field
getQval = function (n) {
var r=new RegExp('[?&;]'+n+'=([^&;#]*)'), m=location.search;
return (m=r.exec(m))? unescape(m[1]) : null;
}, updateForm = function() {
var fname=getQval('fname')? getQval('fname') : 0;
document.forms[fname].elements[field].value=val;
}, val=getQval(field);
if(val){
if ( typeof window.addEventListener != "undefined" )
window.addEventListener( "load", updateForm, false );
else if ( typeof window.attachEvent != "undefined" )
window.attachEvent( "onload", updateForm );
else {
if ( window.onload != null ) {
var oldOnload = window.onload;
window.onload = function ( e ) {
oldOnload( e );
updateForm();
};}
else window.onload = updateForm;}}})();
</script>
</head>
<body>
<form action="ajax.htm">
<div>
<input type="text" name="Something">
</div>
</form>
</body>
</html>
[/HTML]

I downloaded this example: Dowlod this example - very small file!http://www.codylindley.com/blogstuff/js/jtip/
from the net to fix the problem i have with my projects tooltip. We use the 'ALT' on a image to give tooltips so I download a workaround from the net - which works but it displays typed text pages.
so if i had 5 fields with tooltips - i would have to create 5 html pages. So i thought of passing a parameter like you assisted but the tooltip does not picki t up.

The script works great on page1 to page2
but not on the below code: on mouse over it shows the next page with text box but blank-no value - but if I open i new window then the value is there!

Please download the example - i'm not to sure how to fix this!

[HTML]<html>
<body>
This works:<A HREF='ajax.htm?Something=test'>Click here</A>

Example from Net does not like it
<style type='text/css' media='all'>@import 'css/global.css';</style>
<script src='js/jquery.js' type='text/javascript'></script>
<script src='js/jtip.js' type='text/javascript'></script>
<tr>
<td colspan="10" align="center">
<a id="one" href="ajax.htm?Something=test" class="jTip">?</a>
</td>
</tr>


</body>

</html>[/HTML]
Jan 11 '08 #5

acoder
Expert Mod 15k+
P: 16,027
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Jan 11 '08 #6

100+
P: 200
Hi, Thank You
I'm coding in flowcentric whcih uses xslt file for it's stylesheet!

I'm busy with the : Rich HTML Balloon Tooltip

So now I'm trying to incorporate it my xslt file:

The problem i now have that it works, but i can't seem to loop or direct it to the proper value:
The tooltip displays the first value only for all the tooltips
Please, Please Assist!

Expand|Select|Wrap|Line Numbers
  1.  
  2. <link rel="stylesheet" type="text/css" href="balloontip.css" />
  3.  
  4. <script type="text/javascript" src="balloontip.js"></script>
  5.  
  6.  
  7. <xsl:if test="Tooltip != ''">
  8.  
  9. <!-- <xsl:element name="asp:image"> 
  10. <img src="images/tooltip.gif"></img> 
  11. <xsl:attribute name='id'>ttip_<xsl:value-of select='@name' /></xsl:attribute>
  12. <xsl:attribute name='runat'>server</xsl:attribute>
  13. <xsl:attribute name='imageurl'>images/tooltip.gif</xsl:attribute>
  14. <xsl:attribute name='alt'><xsl:value-of select="Tooltip" /></xsl:attribute>-->
  15.  
  16. <a> 
  17. <xsl:attribute name='href'>ajax.htm</xsl:attribute>
  18. <xsl:attribute name='rel'>balloon1</xsl:attribute>??
  19. </a>
  20.  
  21. <div id="balloon1" class="balloonstyle">
  22. <xsl:value-of select="Tooltip" />
  23. </div> 
  24.  
  25. <!--</xsl:element>-->
  26.  
  27. </xsl:if> 
  28. </td>
  29.  
Thank You - if you know xslt - would you please Assist!
Jan 14 '08 #7

acoder
Expert Mod 15k+
P: 16,027
Thank You - if you know xslt - would you please Assist!
I can help you with your original JavaScript problem, but if you have an XSLT related query, you'd probably have more luck in the XML forum.
Jan 15 '08 #8

100+
P: 200
Thank You very much! Really appreciate it.
Jan 15 '08 #9

acoder
Expert Mod 15k+
P: 16,027
Thank You very much! Really appreciate it.
No problem, you're welcome. Good luck!
Jan 15 '08 #10

Post your reply

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