Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Concatenate Strings not Objects

Status
Not open for further replies.

alehambre

Programmer
May 7, 2006
15
US
When the TEST button is clicked, the alert message returns "finalName is [object Attr] Frame Color: [object Attr] ".

How can I make "finalName" return the concatenated strings initialName + currentFrameColor?

I'm new to javascript (and programming). I'm having trouble understanding the handling of objects vs. strings.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"<html xmlns=" xml:lang="en">
<head>
<script type="text/javascript">
<!--
function SymError(){
return true;
}
window.onerror = SymError;
var SymRealWinOpen = window.open;
function SymWinOpen(url, name, attributes){
return (new Object());
}
window.open = SymWinOpen;
//-->
</script>


<!-- Frame Detector -->
<script type="text/javascript">
<!--
//Returns Selected Button
function getSelectedButton(buttonGroup){
for (var i = 0; i < buttonGroup.length; i++) {
if (buttonGroup.checked) {
return i;
}
}
return 0;
}


//Frame Options Detector
function frameOptionDetect(form) {
var i = getSelectedButton(form.frmType);
document.getElementById("total").value = form.frmType.value;
document.getElementById("amount").value = form.frmType.value;
}

//Frame Color Detector
function frameColorDetect(form) {
var i = getSelectedButton(form.frameColor);
var initialName = document.getElementById("item_name").getAttributeNode("value");
var currentFrameColor = form.frameColor.getAttributeNode("value");
var combinedName = initialName.value += " Frame Color: " + currentFrameColor.value;
var finalName = document.getElementById("item_name").getAttributeNode("value");
finalName = combinedName;
alert("finalName is " + finalName);
}


//-->
</script>

</head>

<body>

<!-- Display Image -->
<table name="Full_Page_Table" cellpadding="5" cellspacing="3">
<tr>
<td>
<!-- Start Canned Script -->
<form action=" method="post">

<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value="bobbi@bobbibecker.com">
<input type="hidden" name="item_name" id="item_name" value="bobbi becker print(s): &#34;Pickin Apples&#34;"/>
<input type="hidden" name="item_number" value="003000">
<input type="hidden" name="amount" id="amount" value="">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-ShopCartBF">

<fieldset style="background-color:#CCCCCC" style="padding-left:5; padding-right:5; padding-top:4; padding-bottom:10">
<h3>Frame Specifications</h3>
<!-- Frame Color -->
<div><b>Color</b></div><hr>
<input type="radio" name="frameColor" id="frameColor" onclick="frameColorDetect(this.form)" checked="checked" value="Red" onchange="frameColorDetect(this.form)"/>
<label for="frameColor">Red</label>
<img src="file:///F:/0_WEB/bobbibecker/NEW_<br/>
<input type="radio" name="frameColor" id="frameColor" onclick="frameColorDetect(this.form)" value="Gold" onchange="frameColorDetect(this.form)"/>
<label for="frameColor">Gold</label>
<img src="file:///F:/0_WEB/bobbibecker/NEW_<hr>

<!-- Frame type -->
<div><b>Framing Options</b></div>


<input type="radio" name="frmType" value="15" onclick="frameOptionDetect(this.form)" checked="checked" name="rad"/>
<label for="frmType">Sponged Frame</label>
<br/>

<input type="radio" name="frmType" value="20" onclick="frameOptionDetect(this.form)" name="rad"/>
<label for="frmType">Hand Grained Frame</label>
<br/>

<input type="radio" name="frmType" id="frmType" value="10" onclick="frameOptionDetect(this.form)" name="rad"/><label for="frmType">Unframed</label>
<br/>

</fieldset>
<br/>

Total US&nbsp;&#X0024;&nbsp;&nbsp;<input type="text" id="total" name="total" value="15" size ="6"/>
<br/><br/>
<input type="image" src="images/thumbs/website/x-click-but22.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"/>
<input type="image" src="images/thumbs/website/view_cart_02.gif" alt="Make payments with PayPal - it's fast, free and secure!" onclick="document.forms.viewcart.target = 'paypal'; document.forms.viewcart.submit (); return false;"/>


<p><input type="button" name="Viewer" value="TEST"
onclick="frameColorDetect(this.form)"/></p>


</form>
</td>
<td>
<img src="images/autumn_pickinapples.jpg" alt=""><br/>
<div align="center">
<!--Season=autumn--><span id="PrintName" class="">Pickin Apples</span>
<!--id=003000--><span id="PrintSize" class="">8x10</span>
</div>
</td>
</tr>
</table>


</body>
</html>
 
Because you are using "getAttributeNode", you are getting the attribute as a node, rather than simply the value in the attribute. Try this as a replacement "frameColorDetect" function:

Code:
function frameColorDetect(form) {
	var i = getSelectedButton(form.frameColor);
	var initialName = document.getElementById('item_name').value;
	var currentFrameColour = form.frameColor[i].value;
	var combinedName = initialName + '   Frame Colour: " + currentFrameColour;
	alert('finalName is ' + combinedName);
}

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks for getting back to this so quickly! I'll try it out asap. ;)
 
Dan,

Yes, that part worked! There are other parts that are too complex for me to solve though. Do you know anyone who I can pay to help me get a pay pal page working? I just don't have the time and patience to hack it as a javascript programmer. I'll stick to HTML and XML. ;)

Please let me know if you can recommend someone who has previous experience with small pay pal scripts. I'm not looking for a shopping cart. I just need a few optional items from radio buttons, and a price adjustment to go to the pay pal post.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top