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 8915271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:56:12+00:00 2026-06-15T04:56:12+00:00

is there a work around on how I can pass the value from ‘value’

  • 0

is there a work around on how I can pass the value from ‘value’ going to an if statement?

I get the value now showing 1 or 0. What im trying to accomplish now is how I can pass it in the if statement. I wanted to have something like this. If val = 0 return true; else return false. Im not sure I’m in the right track of using the ajax function. But if there a better way you can show me I will appreciate it.

$(function(){ 
       $('#add_product').click(function(){ 
         var i = $('#product_name').val(); 
         param = 'product_name='+i; 
         check_product(param).done(function(value) {
        var val = value; //value return is 1 or 0 - this is fine
         });
         //val should be past here so that I can determine if I will return true or false
         if(val == 0){
            return true;
         } else{
            return false;
         }
       }); 
    });

function check_product(param){ 
  return $.ajax({ 
    type : 'POST', 
    data : param, 
    url : baseurl+'cart/check_product_name/'
 });
}

html form:

<?php echo form_open_multipart('cart/save_product'); ?>
<h3>Product Name:</h3>
<?php echo form_input(array('name' => 'product_name', 'id' => 'product_name'), set_value('product_name')); ?>
<h3>Price:</h3>
<?php echo form_input(array('name' => 'price', 'id' => 'price'), set_value('price')); ?>
<h3>Status:</h3>
<?php
$options = array(
    '1' => 'Active',
    '0' => 'Not Active'
);
echo form_dropdown('status', $options);
 ?>
<h3>Short Description:</h3>
<?php echo form_textarea(array('name' => 'short_description', 'id' => 'short_desc'), set_value('short_description')); ?>
<h3>Image:</h3>
<?php echo form_upload('userfile'); ?><br>
<p class="submit" id="post_submit"><input type="submit" value="Submit" id="add_product" /></p>
</form>
  • 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-15T04:56:15+00:00Added an answer on June 15, 2026 at 4:56 am

    You’ll need to prevent the form from submitting, and then check with ajax if the product name exists, and when the ajax call has completed do the form submit with javascript if the returned value is zero:

    $(function() {
        $('#add_product').click(function(e) {
            e.preventDefault();
            var i     = $('#product_name').val(),
                param = 'product_name=' + i,
                self  = this;
            check_product(param).done(function(value) {
                if (value === 0) self.submit();
            });
        });
    });
    
    function check_product(param) {
        return $.ajax({
            type: 'POST',
            data: param,
            url: baseurl + 'cart/check_product_name/'
        });
    }​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to work around naming conflicts between Script# and other scripts
I'm currently trying to get my head around the jQuery language. I'm trying to
I am planning to use EJBContext to pass some properties around from the application
Is there any Workaround/Tool for renaming the Resource Keys from the resource file .
Is there a method to pass a variable number of arguments to a function
Is there an attribute that I can place JavaScript into that executes as soon
I have been trying all day to find a way to make this work.
Not sure if this can be done or if there is a good workaround.
I am trying to get the following working. The count loop needs to loop
I am trying to pass a nested array to an asp.net mvc controller like

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.