Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9190949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:34:18+00:00 2026-06-17T20:34:18+00:00

My function in JavaScript/JQuery doesn’t return anything; I want it to return the result

  • 0

My function in JavaScript/JQuery doesn’t return anything; I want it to return the result for me but it won’t. As you can see, the return is the $("#resultado").html("O Valor do produto ficara "+resultado); but this doesn’t appear as it should when the function is run:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">
     $("#target").submit(function(){

    var preco_dolar = $("#preco_dolar").val(); 
    var dolar = $("#dolar").val();
    var frete = $("#frete").val();


    if ($('#drop').is(':checked'))
    {
    var drop = 5.8;
    }else var drop = 0; 


    if(typeof preco_dolar == "undefined"){
        alert("Erro ! Falta preco do produto");
    }

    if(typeof frete == "undefined"){
        var frete = 40;
    }

    if(typeof dolar == "undefined"){
        var dolar = 2.16;
    }




    var resultado = (preco_dolar*dolar)+frete;

    $("#resultado").html("O Valor do produto ficara "+resultado);




});
</script>

Can someone point out where I’m going wrong please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:34:19+00:00Added an answer on June 17, 2026 at 8:34 pm

    First you need to wrap your script into

    // here $("#target") is nothing
    
    $(document).ready(function () {
        // here $("target") exists
    });
    

    Second for your improvement, don’t use

    if(typeof dolar == "undefined"){
        dolar = 2.16;
    }
    

    Use instead

    if(!dolar){
        dolar = 2.16;
    }
    

    That is the same as you would do:

    if(!dolar && dolar == 0 && dolar == "" && dolar == false && dolar == undefined){
        dolar = 2.16;
    }
    

    To make 0 a valid value, use

    if (!dolar && dolar !== 0) {
        dolar = 2.16;
    }
    

    Also don’t use var dolar = 0; twice. If you declared it already, simply use dolar =, to not overwrite the already declared var.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I create an update function in javascript/jquery? An update function is a
How can I check which event called my function on JavaScript with jQuery? Like
When using an importjs() type of function (see below for an example), jQuery doesn't
I want to pass jQuery selectors to a Javascript function Server side. Here is
I'm trying to write a function in Javascript (with jQuery, if you want): function
Is there a way to kill the unload function with javascript(jquery)? I am looking
Is there anyone who knows how to destroy a javascript (jquery) function? I'm using
JavaScript/JQuery var arr=[]; $('.element').each(function(i) { arr.push({id:i,value:$(this).attr('data-value')}); }); $.get('/json.php?arr='+arr,function(result) { alert(result); }); PHP <?php $j
Javascript jQuery event handling If on event (for example 'click') bound one function for
Given the following javascript (jquery) $(#username).keyup(function () { selected.username = $(#username).val(); var url =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.