Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on 

No error, but no value. Why?

Here's my code:

<div id="helper" style="display:none;"></div>
<input id="ord_reviewOrder_submit" type="button" class="btn_base btn_green_60" value="Submit" onclick="$('#ord_reviewOrderError').slideUp().html('');
       if($('#ord_deliveryMethod').val().length == 0 || $('#ord_deliveryCost').val().length == 0)
       var amount = $('#helper').val();
       $('#ord_reviewOrderError').append('A delivery method must be selected to process the order.<br/>');
       [b]$('#ord_reviewOrderError').append('$('#helper).val()');[/b]

Open in new window


What you're looking at is a part of a page that I'm being asked to troubleshoot.

The solution I'm trying to engineer will be looking for the value the API is going to be putting in the "helper" div.

Ultimately, I want to be able to evaluate that value, but for now I'm just trying to reproduce it and I can't get it to show up in the line that I have in bold.

There's no error, but there's no value either.

When I look at the source code, I can see this:

[code]<div id="helper">1000</div>

But I won't see "1000" in the "ord_reviewOrderError" div which is located toward the bottom of the page.

No error, but no value.

What am I missing?
PHPjQuery

Avatar of undefined
Last Comment
Bruce Gust
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
HTML code:
<div id="helper"  style="display:none;" ></div>
<input type="button" id="ord_reviewOrder_submit"  value="submit">

Open in new window


JQuery script
 $('#ord_reviewOrder_submit').on('click',function(){
       $('#ord_reviewOrderError').slideUp().html('');
       if($('#ord_deliveryMethod').val().length === 0 || $('#ord_deliveryCost').val().length === 0){
       var amount = $('#helper').parseInt(text());
       $('#ord_reviewOrderError').append('A delivery method must be selected to process the order.<br/>');
       $('#ord_reviewOrderError').append($('#helper').val());
       }
  });

Open in new window

Just to highlight the problem
$('#ord_reviewOrderError').append('$('#helper).val()');

Open in new window

Look at what is being passed to the append
'$('#helper).val()'

Open in new window

This is a string - it is in quotes so the actual string $('#helper).val() is going to be appended - not the value of #helper

As suggested above you need to pass in the actual value i.e. remove the quotes.
Avatar of Bruce Gust
Bruce Gust
Flag of United States of America image

ASKER

Thank you, guys! It was the "text" dynamic as opposed to "val." That made the difference!
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo