2

I have following Jquery code that alerts a value of an HTML field in this variable $(".attachmentsUpload input.file").val());

My problem is i want to pass this value to variable val like this

window.open("http://abc.com/crop/test.php?val="+$(".attachmentsUpload input.file").val()),"_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");

but its not passing the value.

<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>

      <script type='text/javascript'>//<![CDATA[ 
    $(function(){
    $(".attachmentsUpload input.file").live("change", function () {
        if ($(".attachmentsUpload input.file").val() == "") {
            return;
        }
        // your ajax submit
        alert("submit value of the file input field=" + $(".attachmentsUpload input.file").val());


        $(".attachmentsUpload input.file").replaceWith('<input type="file" class="file" name="file" />');
    });
    });//]]>  

    window.open("http://abc.com/crop/test.php?val="+$(".attachmentsUpload input.file").val()),"_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");

    </script>
</head>
<body>
  <form class="attachmentsUpload" action="/UploadHandler.ashx" method="post" enctype="multipart/form-data">
    <input type="file" class="file" name="file" />

</form>
</body>
</html>
4
  • Please show your html, especialy this input. PS. Don't use live(), use on() instead. Commented May 31, 2013 at 14:07
  • 3
    Looks like you have an extra close parenth in the window.open statement. Try changing val()) to val()? Commented May 31, 2013 at 14:07
  • @ckpepper02 HTML added Commented May 31, 2013 at 14:09
  • Made my comment an answer if that solved your problem. Commented May 31, 2013 at 14:15

2 Answers 2

1

As i understand it:

$(".attachmentsUpload input.file").replaceWith('<input type="file" class="file" name="file" />');

So then:

$(".attachmentsUpload input.file").val() returns string empty

Sign up to request clarification or add additional context in comments.

Comments

1

Looks like you have an extra close parenth in the window.open statement. Try changing val()) to val()

So:

window.open("http://abc.com/crop/test.php?val="+$(".attachmentsUpload input.file").val()+","_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.